Skip to content

Commit 7a1ecc2

Browse files
committed
Time: 25 ms (51.48%), Space: 82 MB (6.57%) - LeetHub
1 parent 7245bd5 commit 7a1ecc2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
// TC : O(n)
3+
// SC : O(n)
4+
public String addSpaces(String s, int[] spaces) {
5+
StringBuilder sb = new StringBuilder();
6+
int start=0;
7+
for(int i=0;i<spaces.length; i++){
8+
sb.append(s.substring(start,spaces[i]));
9+
sb.append(" ");
10+
start=spaces[i];
11+
}
12+
sb.append(s.substring(start,s.length()));
13+
return sb.toString();
14+
}
15+
}

0 commit comments

Comments
 (0)