leetcodeブラシ問題、まとめ、記録、メモ344
674 ワード
leetcode344
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
基礎問題、何も言うことはありません.
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
基礎問題、何も言うことはありません.
class Solution {
public:
string reverseString(string s) {
if (s.size() == 0)
{
return s;
}
int m = s.size() / 2;
for(int i = 0; i < m; ++ i)
{
char t = s[i];
s[i] = s[s.size() - 1 - i];
s[s.size() - 1 - i] = t;
}
return s;
}
};