3090. 每个字符最多出现两次的最长子字符串
This commit is contained in:
+13
-24
@@ -6,36 +6,25 @@ mod tree;
|
|||||||
|
|
||||||
struct Solution {}
|
struct Solution {}
|
||||||
impl Solution {
|
impl Solution {
|
||||||
pub fn decode_string(s: String) -> String {
|
pub fn maximum_length_substring(s: String) -> i32 {
|
||||||
let mut st = vec![];
|
let s = s.bytes().map(|x| x as usize).collect::<Vec<_>>();
|
||||||
let mut local = "".to_string();
|
let mut arr = vec![0; 'z' as usize + 1];
|
||||||
let mut cnt = 0;
|
let mut l = 0;
|
||||||
// let mut layer = 0;
|
let mut ans = 0;
|
||||||
for c in s.chars() {
|
for r in 0..s.len() {
|
||||||
if c.is_ascii_digit() {
|
arr[s[r]] += 1;
|
||||||
cnt = cnt * 10 + c.to_digit(10).unwrap() as usize;
|
while arr[s[r]] > 2 {
|
||||||
continue;
|
arr[s[l]] -= 1;
|
||||||
|
l += 1;
|
||||||
}
|
}
|
||||||
if c == '[' {
|
ans = ans.max(r - l + 1);
|
||||||
st.push((local,cnt));
|
|
||||||
cnt = 0;
|
|
||||||
local = "".to_string();
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if c == ']' {
|
ans as i32
|
||||||
let (mut str, cnt) = st.pop().unwrap();
|
|
||||||
str += &local.repeat( cnt);
|
|
||||||
local = str;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
local.push(c);
|
|
||||||
}
|
|
||||||
local
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
println!(
|
println!(
|
||||||
"{:?}",
|
"{:?}",
|
||||||
Solution::decode_string("3[a2[c]]".to_string())
|
Solution::maximum_length_substring("bcbbbcba".to_string())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user