算法打卡第一周
Leetcode第1528题:重新排列字符串
class Solution {
public String restoreString(String s, int[] indices) {
char[] chars = new char[indices.length];
for (int i =0;i<indices.length;i++) {
chars[indices[i]] = s.charAt(i);
}
return new String(chars);
}
}
Leetcode第1893题:URL化
class Solution {
public String replaceSpaces(String S, int length) {
if(S==null || S.length()==0 || length<=0) {
return "";
}
StringBuilder sb = new StringBuilder();
for(int i =0;i<length;i++) {
char character = S.charAt(i);
if(character==' '){
sb.append("%20");
}else {
sb.append(character);
}
}
return sb.toString();
}
}