344 Reverse String 反转字符串
请编写一个函数,其功能是将输入的字符串反转过来。
示例:
输入:s = "hello"
返回:"olleh"
详见:https://leetcode.com/problems/reverse-string/description/
C++:
class Solution { public: string reverseString(string s) { int n=s.size(); if(n==0||s.empty()) { return ""; } int left=0,right=n-1; while(left<right) { char tmp=s[left]; s[left]=s[right]; s[right]=tmp; ++left; --right; } return s; } };