编程语言
首页 > 编程语言> > 反转字符串 Java

反转字符串 Java

作者:互联网

力扣题目链接
位运算

class Solution {
    public void reverseString(char[] s) {
        int l = 0;
        int r = s.length - 1;
        while(l<r){
            s[l] ^= s[r];//s[l] = a^b
            s[r] ^= s[l];//s[r] = b^a^b = a;
            s[l] ^= s[r];//s[l] = a^b^a = b;

            l++;
            r--;
        }
    }
}

标签:reverseString,Java,int,反转,void,Solution,char,字符串
来源: https://www.cnblogs.com/jianjiana/p/15859169.html