您的位置:首页 > 其它

Leetcode no. 344

2016-05-25 17:11 288 查看
344. Reverse String

Write a function that takes a string as input and returns the string reversed.

Example:

Given s = "hello", return "olleh".

public class Solution {
public String reverseString(String s) {
if (s.length()==0) return s;
char[] c= s.toCharArray();
int i=0, j=c.length-1;
while (i<j){
char tmp= c[i];
c[i]=c[j];
c[j]=tmp;
i++; j--;
}
return new String(c);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: