思路:在原来的字符串后面添加上strlen-1个字符,返回
class Solution { public: string reverseString(string s) { unsigned int strlen; int i; // char temp; strlen = s.size(); if (strlen > 1) { for (i = strlen - 2; i >= 0 ; i--) { // temp = s[i]; s += s[i]; } return s.substr(strlen - 1 , strlen + strlen - 2); } else return s; } };
时间: 2024-10-15 13:47:25