Skip to content

Commit 921d2d5

Browse files
authored
Update 484-find-permutation.js
1 parent 7e0ca72 commit 921d2d5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

484-find-permutation.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* @param {string} s
3+
* @return {number[]}
4+
*/
5+
const findPermutation = function(s) {
6+
const n = s.length
7+
const res = Array(n + 1)
8+
res[n] = n + 1
9+
for (let i = 0, len = n; i < len;) {
10+
let j = i;
11+
while (j < len && s.charAt(j) === 'D') {
12+
j++;
13+
}
14+
for (let k = j - i; k >= 0; k--, j--) {
15+
res[i++] = j + 1;
16+
}
17+
}
18+
return res;
19+
};
20+
21+
// another
22+
123
/**
224
* @param {string} s
325
* @return {number[]}

0 commit comments

Comments
 (0)