爱程序网

344. Reverse String

来源: 阅读:

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

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

代码如下:

方法一:(java)

1 public class Solution {
2     public String reverseString(String s) {
3 
4         StringBuffer t=new StringBuffer(s);
5         return t.reverse().toString();
6     }
7 }

 方法二:(c++)

1 class Solution {
2 public:
3     string reverseString(string s) {
4         reverse(s.begin(),s.end());
5         return s;
6     }
7 };

 

关于爱程序网 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助