Skip to content

Commit

Permalink
Create 2109. Adding Spaces to a String (#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Dec 3, 2024
2 parents e9d3dd2 + f9b7ec8 commit 955df7a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 2109. Adding Spaces to a String
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public:
string addSpaces(string s, vector<int>& spaces) {
int ind = 0;
string ans = "";
for (int i = 0; i < s.size(); i++) {
if (ind < spaces.size() && i == spaces[ind]) {
ans += " ";
ind++;
}
ans += s[i];
}
return ans;
}
};

0 comments on commit 955df7a

Please sign in to comment.