public class Solution {
public void reverseString(char[] s) {
int high=s.length-1;
reverset(s,0,high);
}
private void reverset(char[] s,int low,int high){
if(low==high||low>high){
return;
}if(low<high){
char temp;
temp=s[low];
s[low]=s[high];
s[high]=temp;
}
reverset(s,++low,--high);
}
}
測試入口:
public static void main(String[] args) {
char[] s={'h','e','l','l','o'};
Solution solution=new Solution();
solution.reverseString(s);
System.out.println(s);
}