Skip to content

Commit a9f28a4

Browse files
authored
Create 2405-optimal-partition-of-string.js
1 parent 7fb3216 commit a9f28a4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

2405-optimal-partition-of-string.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var partitionString = function(s) {
6+
let res = 0, n = s.length
7+
let i = 0, j = 0, num = 0
8+
const set = new Set()
9+
for(let i = 0; i < n; i++) {
10+
const ch = s[i]
11+
if(set.has(ch)) {
12+
res++
13+
num = 1
14+
set.clear()
15+
} else {
16+
17+
}
18+
set.add(ch)
19+
}
20+
21+
return res + 1
22+
};

0 commit comments

Comments
 (0)