leetcode 344. Reverse String

来源:互联网 发布:金十数据app 编辑:程序博客网 时间:2024/06/09 08:19
344. 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 n=s.size();        int i=0;        int j=n-1;        while(i<=j) {            if (s[i] != s[j])                swap(s[i], s[j]);            i++;            j--;        }        return s;    }};