LeetCode 344: Reverse String (字符串翻转)

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

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

Note:1.注意空间复杂度,不需要重新分配内存,直接在原字符串上进行操作。 2.swap()函数的使用, swap函数原型如下:

template  void swap ( T& a, T& b )  
{  
  T c(a); a=b; b=c;  
} 


Code:
class Solution {
public:
    string reverseString(string s) {
        int i=0, j = s.length()-1;
        while(i


你可能感兴趣的:(LeetCode,easy)