Skip to content

Commit 834c26e

Browse files
authored
Update 942-di-string-match.js
1 parent 5e2f011 commit 834c26e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

942-di-string-match.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,20 @@ const diStringMatch = function(S) {
1919
res.push(arr.pop())
2020
return res
2121
};
22+
23+
// another
24+
25+
/**
26+
* @param {string} s
27+
* @return {number[]}
28+
*/
29+
const diStringMatch = function(s) {
30+
const n = s.length
31+
let l = 0, r = n
32+
const res = []
33+
for(let i = 0; i < n; i++) {
34+
res.push(s[i] === 'I' ? l++ : r--)
35+
}
36+
res.push(r)
37+
return res
38+
};

0 commit comments

Comments
 (0)