标签:
// 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; } };
标签:
原文地址:http://www.cnblogs.com/blankquiz/p/5909990.html