天天看点

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++;
        }
    }
}