反转字符串

75 阅读1分钟

344 反转字符串

class Solution {
    public void reverseString(char[] s) {
        for (int i = 0; i < s.length / 2; i++) {
            //当i等于数组中间索引位置时,则跳出,避免交换过度
            char c = s[i];
            s[i] = s[s.length - 1 - i];
            s[s.length - 1 - i] = c;
        }
    }
}