344、反转字符串
基本思想:
双指针中的左右指针
具体实现:
代码:
class Solution { public void reverseString(char[] s) { for (int i = 0, j = s.length - 1; i < j; i++, j--){ char temp = s[i]; s[i] = s[j]; s[j] = temp; } } }
2023-10-09 15:01:34
双指针中的左右指针
class Solution { public void reverseString(char[] s) { for (int i = 0, j = s.length - 1; i < j; i++, j--){ char temp = s[i]; s[i] = s[j]; s[j] = temp; } } }