344. Reverse String

来源:互联网 发布:java timestamp是什么 编辑:程序博客网 时间:2024/05/09 00:42

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

Example:
Given s = “hello”, return “olleh”.

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