Skip to content

Commit 109190f

Browse files
committed
hash
1 parent 402da82 commit 109190f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎Med1593.java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.HashSet;
2+
import java.util.Set;
3+
4+
5+
class Med1593 {
6+
public int maxUniqueSplit(String s) {
7+
dfs(s, 0, new HashSet<>());
8+
return ans;
9+
}
10+
11+
private int ans = 0;
12+
13+
private void dfs(final String s, int start, Set<String> seen) {
14+
if (start == s.length()) {
15+
ans = Math.max(ans, seen.size());
16+
return;
17+
}
18+
19+
for (int i = start + 1; i <= s.length(); ++i) {
20+
final String cand = s.substring(start, i);
21+
if (seen.contains(cand))
22+
continue;
23+
seen.add(cand);
24+
dfs(s, i, seen);
25+
seen.remove(cand);
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)