761. 特殊的二进制字符串
This commit is contained in:
parent
54bea679f0
commit
0f894b29a8
43
src/main.rs
43
src/main.rs
|
|
@ -1,27 +1,36 @@
|
||||||
struct Solution;
|
struct Solution;
|
||||||
mod arr;
|
mod arr;
|
||||||
|
|
||||||
impl Solution {
|
impl Solution {
|
||||||
pub fn next_greatest_letter(letters: Vec<char>, target: char) -> char {
|
pub fn sp(s : &str)-> String{
|
||||||
let mut index = 1e5 as usize;
|
if s.len() <= 2 {
|
||||||
for i in 0..letters.len() {
|
return s.to_string();
|
||||||
if letters[i] > target {
|
}
|
||||||
if index == 1e5 as usize {
|
let mut left = 0;
|
||||||
index = i;
|
let mut cnt = 0;
|
||||||
} else {
|
let sb = s.as_bytes();
|
||||||
if letters[i] < letters[index] {
|
let mut arr = Vec::new();
|
||||||
index = i;
|
for i in 0..s.len() {
|
||||||
}
|
if sb[i] == b'1' {
|
||||||
}
|
cnt += 1;
|
||||||
|
}else {
|
||||||
|
cnt -= 1;
|
||||||
|
}
|
||||||
|
if cnt == 0 {
|
||||||
|
arr.push(format!("1{}0",Self::sp(&s[left + 1 .. i])));
|
||||||
|
left = i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if index == 1e5 as usize {
|
arr.sort_unstable_by(|a,b| b.cmp(a));
|
||||||
letters[0]
|
arr.join("")
|
||||||
} else {
|
}
|
||||||
letters[index]
|
pub fn make_largest_special(s: String) -> String {
|
||||||
}
|
Self::sp(s.as_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
let result = Solution::next_greatest_letter(vec!['c', 'f', 'j'], 'a');
|
let result = Solution::make_largest_special(
|
||||||
|
"101101101010101010001010101010110011011010001100".to_string(),
|
||||||
|
);
|
||||||
println!("{:?}", result);
|
println!("{:?}", result);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue