Skip to content

Commit 59af257

Browse files
Merge pull request #2702 from leahjia/2405-optimal-partition-of-string
Created 2405-optimal-partition-of-string.java
2 parents bd8d52a + 278fbd8 commit 59af257

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int partitionString(String s) {
3+
Set<Character> set = new HashSet<>();
4+
int res = 1;
5+
for (char ch : s.toCharArray()) {
6+
if (set.contains(ch)) {
7+
set = new HashSet<>();
8+
res++;
9+
}
10+
set.add(ch);
11+
}
12+
return res;
13+
}
14+
}

0 commit comments

Comments
 (0)