C++
class Solution {
public:
string reverseString(string s) {
string result="";
for(int i=1;i<=s.length();i++)
{
result+=s[s.length()-i];
}
return result;
}
};
Java
public class Solution {
public String reverseString(String s) {
return new StringBuffer(s).reverse().toString();
}
}
Javascript
/**
* @param {string} s
* @return {string}
*/
var reverseString = function(s) {
return s.split("").reverse().join("");
};
最優(yōu)解
位交換