1.同數字陣列
2.主要注意邊界為 s.length-i-1
1 class Solution { 2 public void reverseString(char[] s) { 3 for(int i=0;i<s.length/2;i++){ 4 char tep; 5 tep=s[i]; 6 s[i]=s[s.length-i-1]; 7 s[s.length-i-1]=tep; 8 } 9 10 } 11 }
1.同數字陣列
2.主要注意邊界為 s.length-i-1
1 class Solution { 2 public void reverseString(char[] s) { 3 for(int i=0;i<s.length/2;i++){ 4 char tep; 5 tep=s[i]; 6 s[i]=s[s.length-i-1]; 7 s[s.length-i-1]=tep; 8 } 9 10 } 11 }