反转字符串 (Reverse String)

 

思路:

// @Title: 反转字符串 (Reverse String)
// @Author: qisiii
// @Date: 2024-09-12 01:54:00
// @Runtime: 0 ms
// @Memory: 44.4 MB
// @comment: 
// @flag: 
class Solution {
    public void reverseString(char[] s) {
        int left=0,right=s.length-1;
        while(left<right){
            char temp=s[left];
            s[left]=s[right];
            s[right]=temp;
            left++;right--;
        }
    }
}

+++ title = “反转字符串 (Reverse String)” draft = false +++

思路:

// @Title: 反转字符串 (Reverse String)
// @Author: qisiii
// @Date: 2022-02-28 21:19:32
// @Runtime: 1 ms
// @Memory: 47.6 MB
// @comment: 
// @flag: 
class Solution {
    public void reverseString(char[] s) {
        for(int i=0;i<s.length/2;i++){
            char temp=s[i];
            s[i]=s[s.length-1-i];
            s[s.length-1-i]=temp;
        }
    }
}

思路:

// @Title: 反转字符串 (Reverse String)
// @Author: qisiii
// @Date: 2022-03-10 19:38:40
// @Runtime: 0 ms
// @Memory: 48 MB
// @comment: 
// @flag: 
class Solution {
    public void reverseString(char[] s) {
        int left=0,right=s.length-1;
        char temp=' ';
        while(left<right){
            temp=s[left];
            s[left]=s[right];
            s[right]=temp;
            left++;right--;
        }
    }
}
Licensed under CC BY-NC-SA 4.0
最后更新于 2024-10-18