第二题这样应该简洁一点 class Solution { public String replaceSpace(String s) { StringBuilder res = new StringBuilder(); for(Character c : s.toCharArray()) { if(c == ' ') res.append("%20"); else res.append(c); } return res.toString(); } }