impl Solution { pub fn longest_decomposition(text: String) -> i32 { let (mut ans, n) = (0, text.len()); let (mut l, mut r) = (String::from(""), String::from("")); for i in 0..n { l.push(text.chars().nth(i).unwrap()); r.insert(0, text.chars().nth(n - i - 1).unwrap()); if l == r { ans += 1; l.clear(); r.clear(); } } return ans; } }
|