力扣题解 344th 反转字符串

344th 反转字符串

  • 双指针法

    双指针法是非常常用的算法,也很容易理解。

    class Solution {
        public void reverseString(char[] s) {
            int i = 0, j = s.length - 1;
            while(i <= j) {
                char t = s[i];
                s[i] = s[j];
                s[j] = t;
                i++;
                j--;
            }
        }
    }
    
原文地址:https://www.cnblogs.com/fromneptune/p/13236653.html