Skip to content

Commit 503b8c4

Browse files
authored
Create Adding Spaces to a String.java
1 parent 35fe776 commit 503b8c4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Medium/Adding Spaces to a String.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public String addSpaces(String s, int[] spaces) {
3+
StringBuilder sb = new StringBuilder();
4+
int startIdx = 0;
5+
for (int spaceIdx : spaces) {
6+
sb.append(s.substring(startIdx, spaceIdx)).append(" ");
7+
startIdx = spaceIdx;
8+
}
9+
sb.append(s.substring(startIdx));
10+
return sb.toString();
11+
}
12+
}

0 commit comments

Comments
 (0)