请编写一个函数,其功能是将输入的字符串反转过来。
C++
class Solution { public: string reverseString(string s) { int left = 0, right = s.size() - 1; while (left < right) { swap(s[left++], s[right--]); } return s; } };
C
char* reverseString(char* s) { int t,left = 0, right = strlen(s) - 1; while (left < right) { t = s[left]; s[left++] = s[right]; s[right--] = t; } return s; }
原文地址:https://www.cnblogs.com/moonpie-sun/p/9425522.html
时间: 2024-10-10 04:25:00