您的位置:首页 > 其它

LeetCOde 344. Reverse String

2016-09-03 08:56 471 查看

LeetCOde 344. Reverse String

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

Example:

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

Subscribe to see which companies asked this question
水题,注意判断条件是i<=j 不是i!=j
string reverseString(string s)
{
int len=s.length();
char temp;
for(int i=0,j=len-1;i<=j;i++,j--)
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
return s;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: