Skip to content

Commit

Permalink
Time: 26 ms (40.66%), Space: 80.4 MB (65.66%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
kasmeen123 committed Dec 3, 2024
1 parent 131fbf5 commit b8f4e42
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 2109-adding-spaces-to-a-string/2109-adding-spaces-to-a-string.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public String addSpaces(String s, int[] spaces) {

int index = 0;
StringBuilder ans = new StringBuilder();
for(int i = 0; i < s.length(); i++) {
if(index < spaces.length && i == spaces[index]) {
ans.append(" ");
index++;
}
ans.append(s.charAt(i));
}
return ans.toString();
}
}

0 comments on commit b8f4e42

Please sign in to comment.