天天看點

leetcode344.反轉字元串

開始學習字元串處理了,先來個開胃小菜,秒了!

https://leetcode-cn.com/problems/reverse-string/

class Solution {
    public void reverseString(char[] s) {
        int left = 0, right = s.length - 1;
        char temp;
        while(left < right){
            temp = s[left];
            s[left] = s[right];
            s[right] = temp;
            
            right--;
            left++;
        }
    }
}