字符串反转(力扣题库)

 public static void main(String[] args) {

        reverse(new char[]{'a','b','c'});

    }

    public static void reverse(char[] s){
        for (int i = 0; i <(int)(s.length/2); i++) {
            s[i]=(char)(((int)s[i])+((int)s[s.length-i-1]));
            s[s.length-i-1]=(char)(((int)s[i])-((int)s[s.length-i-1]));
            s[i]=(char)(((int)s[i])-((int)s[s.length-i-1]));
        }
        for (int i = 0; i < s.length; i++) {
            System.out.print(s[i]);
        }

    }

你可能感兴趣的:(java算法)