题目链接
1 <= s.length <= 105
s[i] 都是 ASCII 码表中的可打印字符
示例 1:
输入:s = ["h","e","l","l","o"]
输出:["o","l","l","e","h"]
示例 2:
输入:s = ["H","a","n","n","a","h"]
输出:["h","a","n","n","a","H"]
package q344反转字符串;
public class Main {
public static void main(String[] args) {
char[] s={'1','2','3','4','5','6'};
reverseString(s);
for (char ss:s){
System.out.print(" "+ss);
}
}
public static void reverseString(char[] s) {
char t;
for (int i=0;i<s.length/2;i++){
t=s[i];
s[i]=s[s.length-1-i];
s[s.length-1-i]=t;
}
}
}