344. 反转字符串

class Solution {
    public String reverseString(String s) {
        char[] cs = s.toCharArray();
        int left = 0;
        int right = cs.length - 1;

        while (left < right) {
            cs[left] = (char)(cs[left] ^ cs[right]);
            cs[right] = (char)(cs[left] ^ cs[right]);
            cs[left] = (char)(cs[left] ^ cs[right]);
            left++;
            right--;
        }

        return new String(cs);
    }
}
image.png

你可能感兴趣的:(344. 反转字符串)