image.png

解题思路

双指针

  1. public void reverseString(char[] s) {
  2. if(s == null || s.length < 2)
  3. return;
  4. int left = -1;
  5. int right = s.length;
  6. while(++left < --right){
  7. char c = s[left];
  8. s[left] = s[right];
  9. s[right] = c;
  10. }
  11. return;
  12. }