Skip to content

Commit e21aad2

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

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

484-find-permutation.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ const findPermutation = function(s) {
1818
return res;
1919
};
2020

21+
// another
22+
23+
/**
24+
* @param {string} s
25+
* @return {number[]}
26+
*/
27+
const findPermutation = function(s) {
28+
const n = s.length
29+
const res = Array(n)
30+
res[n] = n + 1
31+
for(let i = 0; i < n;) {
32+
let j = i
33+
while(j < n && s[j] === 'D') j++
34+
// console.log(j)
35+
for(let k = j - i + 1; k > 0; k--) {
36+
res[i] = j + 1
37+
i++
38+
j--
39+
}
40+
}
41+
42+
return res
43+
};
44+
45+
2146
// another
2247

2348
/**

0 commit comments

Comments
 (0)