344. Reverse String

https://leetcode.com/problems/reverse-string/description/

代码:
class Solution {
public String reverseString(String s) {
/****第一种方法用StringBuilder****/
// StringBuilder str = new StringBuilder(s);
// return str.reverse().toString();
/第二种方法用toCharArray和new String 转字符串和字符数组*/
char[] c = s.toCharArray();
int len = s.length();
int start = 0, end = len - 1;
while(start < end){
char temp = c[start];
c[start] = c[end];
c[end] = temp;
start++;
end--;
}
return new String(c);
}
}

你可能感兴趣的:(344. Reverse String)