Skip to content

Commit c32e88e

Browse files
authored
Create 5957-adding-spaces-to-a-string.js
1 parent b3e4761 commit c32e88e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

5957-adding-spaces-to-a-string.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {string} s
3+
* @param {number[]} spaces
4+
* @return {string}
5+
*/
6+
var addSpaces = function(s, spaces) {
7+
let res = '', j = 0, idx = spaces[j]
8+
for(let i = 0, n = s.length; i < n; i++) {
9+
if(i === idx) {
10+
res += ' '
11+
j++
12+
idx = spaces[j]
13+
}
14+
res += s[i]
15+
}
16+
17+
return res
18+
};

0 commit comments

Comments
 (0)