1
use std::collections::HashSet;
2

3
impl Solution {
4
pub fn max_unique_split(s: String) -> i32 {
5
let mut combos = HashSet::new();
6
let mut max = 0;
7
let chars: Vec<String> = s.chars().map(|c| c.to_string()).collect();
8
Self::helper(&mut combos, &chars, &mut max);
9

10
max as i32
11
}
12

13
fn helper(combos: &mut HashSet<String>, chars: &[String], max: &mut usize) {
14
if !chars.is_empty() {
15
for i in 0..chars.len() {
16
let mut substr = chars[0..i + 1]
17
.iter()
18
.fold(String::with_capacity(i), |mut new_str, s| {
19
new_str.push_str(s);
20
new_str
21
});
22
if !combos.contains(&substr) {
23
combos.insert(substr.clone());
24
Self::helper(combos, &chars[i + 1..], max);
25
combos.remove(&substr);
26
}
27
}
28
} else {
29
if combos.len() > *max {
30
*max = combos.len();
31
}
32
}
33
}
34
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0