Reverse String

LeetCode #344


Description:

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

Example:

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

Idea:

简单。

Code:

class Solution {
public:
    string reverseString(string s) {
        int i=0;
        int j=s.size()-1;
        while(i<j){
            swap(s[i], s[j]);
            i++;
            j--;
        }

        return s;     
    }
};

results matching ""

    No results matching ""