1. 程式人生 > >【LeetCode & 劍指offer刷題】字串題3:Reverse String

【LeetCode & 劍指offer刷題】字串題3:Reverse String

【LeetCode & 劍指offer 刷題筆記】目錄(持續更新中...)

Reverse String

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

 

Example: Given s = "hello", return "olleh".   /*class Solution {
public:     string reverseString(string s)     {         int i = 0;         int j = s.size() - 1;         while(i<j)
        {             swap(s[i++],s[j--]);         }                 return s;
    } };*/ class Solution { public :     string reverseString ( string s )     {         reverse ( s . begin (), s . end ());         return s ;     } };