码迷,mamicode.com
首页 > 其他好文 > 详细

344. Reverse String

时间:2016-09-26 18:01:01      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

// My own solution
class
Solution { public: string reverseString(string s) { return string(s.crbegin(), s.crend()); } };
// My own solution
class
Solution { public: string reverseString(string s) { int n = s.size(); const char *p = s.c_str() + ((n - 1) * sizeof(char)); string str; for(int i = 0; i < n; i++){ str += *p; p = p - sizeof(char); } return str; } };
// Learning from others‘ ideas
class
Solution { public: string reverseString(string s) { int n = s.size(); for(int i = 0; i < n / 2; i++){ char tmp = s[i]; s[i] = s[n - 1 - i]; s[n - 1 - i] = tmp; } return s; } };

 

344. Reverse String

标签:

原文地址:http://www.cnblogs.com/blankquiz/p/5909990.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!