Find the Longest Substring Containing Vowels in Even Counts LeetCode solution in Rust

1
impl Solution {
2
pub fn find_the_longest_substring(s: String) -> i32 {
3
let s = s.chars().collect::<Vec<char>>();
4
let n = s.len();
5
let limit = 1 << 5;
6
let mut memo = vec![vec![]; limit];
7

8
let dict = ['a', 'i', 'u', 'e', 'o'];
9
let mut now = 0;
10
for i in 0..n {
11
memo[now].push(i);
12
for j in 0..5 {
13
if s[i] == dict[j] {
14
let v = 1 << j;
15
now ^= v;
16
break;
17
}
18
}
19
}
20
memo[now].push(n);
21

22
let mut result = 0;
23
let mut i = 0;
24
for arr in memo {
25
if arr.len() >= 2 {
26
result = result.max(arr[arr.len() - 1] - arr[0]);
27
}
28
i += 1;
29
}
30

31
result as i32
32
}
33
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0