2109. Adding Spaces to a String
T: O(s len+ space array size)
S: O(s len+ space array size)
class Solution {
public String addSpaces(String s, int[] spaces) {
StringBuilder sb = new StringBuilder();
int start = 0;
for (int space : spaces) {
sb.append(s.substring(start, space)).append(" ");
start = space;
}
sb.append(s.substring(start, s.length()));
return sb.toString();
}
}ja
Previous2108. Find First Palindromic String in the ArrayNext2110. Number of Smooth Descent Periods of a Stock
Last updated
Was this helpful?