From d19b5d9ca8c9b3b38bf54296c8aae8e3068381e1 Mon Sep 17 00:00:00 2001 From: li-chx Date: Fri, 14 Aug 2026 20:20:45 +0800 Subject: [PATCH] =?UTF-8?q?3090.=20=E6=AF=8F=E4=B8=AA=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E6=9C=80=E5=A4=9A=E5=87=BA=E7=8E=B0=E4=B8=A4=E6=AC=A1=E7=9A=84?= =?UTF-8?q?=E6=9C=80=E9=95=BF=E5=AD=90=E5=AD=97=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/main.rs b/src/main.rs index 972a2b6..d05e0d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,36 +6,25 @@ mod tree; struct Solution {} impl Solution { - pub fn decode_string(s: String) -> String { - let mut st = vec![]; - let mut local = "".to_string(); - let mut cnt = 0; - // let mut layer = 0; - for c in s.chars() { - if c.is_ascii_digit() { - cnt = cnt * 10 + c.to_digit(10).unwrap() as usize; - continue; + pub fn maximum_length_substring(s: String) -> i32 { + let s = s.bytes().map(|x| x as usize).collect::>(); + let mut arr = vec![0; 'z' as usize + 1]; + let mut l = 0; + let mut ans = 0; + for r in 0..s.len() { + arr[s[r]] += 1; + while arr[s[r]] > 2 { + arr[s[l]] -= 1; + l += 1; } - if c == '[' { - st.push((local,cnt)); - cnt = 0; - local = "".to_string(); - continue; - } - if c == ']' { - let (mut str, cnt) = st.pop().unwrap(); - str += &local.repeat( cnt); - local = str; - continue; - } - local.push(c); + ans = ans.max(r - l + 1); } - local + ans as i32 } } fn main() { println!( "{:?}", - Solution::decode_string("3[a2[c]]".to_string()) + Solution::maximum_length_substring("bcbbbcba".to_string()) ); }