Skip to content

Commit 955df7a

Browse files
authored
Create 2109. Adding Spaces to a String (#650)
2 parents e9d3dd2 + f9b7ec8 commit 955df7a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

2109. Adding Spaces to a String

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
string addSpaces(string s, vector<int>& spaces) {
4+
int ind = 0;
5+
string ans = "";
6+
for (int i = 0; i < s.size(); i++) {
7+
if (ind < spaces.size() && i == spaces[ind]) {
8+
ans += " ";
9+
ind++;
10+
}
11+
ans += s[i];
12+
}
13+
return ans;
14+
}
15+
};

0 commit comments

Comments
 (0)