Skip to content

Commit 2dd132a

Browse files
authored
Create 2405-optimal-partition-of-string.kt
1 parent 4dd3163 commit 2dd132a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
fun partitionString(s: String): Int {
3+
val hs = HashSet<Char>()
4+
var res = 0
5+
6+
for (c in s) {
7+
if (hs.contains(c)) {
8+
res++
9+
hs.clear()
10+
}
11+
hs.add(c)
12+
}
13+
14+
return if(hs.size != 0) res + 1 else res
15+
}
16+
}

0 commit comments

Comments
 (0)