题解 | #斐波那契数列#
替换空格
http://www.nowcoder.com/practice/0e26e5551f2b489b9f58bc83aa4b6c68
//复杂度为n? public static String replaceSpace (String s) {public static String replaceSpace (String s) { // write code here if(s==null || s.length()==0){ return ""; } int nuSpace = 0 ; for(int i = 0 ; i < s.length();i++){ if(s.charAt(i) == ' '){ nuSpace++; } } char[] array = s.toCharArray(); int preLength = array.length; int aftLength = preLength + 2*nuSpace; char[] temp = new char[aftLength]; int j = 0; for(int i = 0 ; i < preLength ; i++){ temp[j] = array[i]; if(temp[j] == ' '){ temp[j] = '%'; temp[j+1] = '2'; temp[j+2] = '0'; j+=2; } j++; } String s1 = new String(); for(int i = 0 ; i < temp.length ; i++){ s1 += temp[i] + ""; } return s1; }