Skip to content

Commit 22cea6e

Browse files
authored
Create 2109. Adding Spaces to a String
1 parent c69a8a5 commit 22cea6e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

2109. Adding Spaces to a String

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
string addSpaces(string s, vector<int>& spaces) {
4+
int m = s.length();
5+
int n = spaces.size();
6+
7+
string result = "";
8+
9+
int j = 0; //to traverse in spaces vector
10+
for(int i = 0; i < m; i++) {
11+
if(j < n && i == spaces[j]) {
12+
result += " ";
13+
j++;
14+
}
15+
16+
result += s[i];
17+
}
18+
19+
return result;
20+
}
21+
};

0 commit comments

Comments
 (0)