代码随想录算法训练营第8天| LeetCode 344.反转字符串 541. 反转字符串II剑指Offer 05.替换空格151.翻转字符串里的单词剑指Offer58-II.左旋转字符串

344.反转字符串

class Solution {
    public void reverseString(char[] s) {
        int left = 0;
        int right = s.length -1;
        while(left < right){
            char temp = s[left];

            s[left] = s[right];
            s[right] = temp;
            left++;
            right--;
        }
       

    }
}

541. 反转字符串II

class Solution {
    public void reverseString(char[] s) {
        int left = 0;
        int right = s.length -1;
        while(left < right){
            char temp = s[left];

            s[left] = s[right];
            s[right] = temp;
            left++;
            right--;
        }
       

    }
}

你可能感兴趣的:(代码随想录算法训练营,算法,leetcode,java)