1 static int wing=[]() 2 { 3 std::ios::sync_with_stdio(false); 4 cin.tie(NULL); 5 return 0; 6 }(); 7 8 class Solution 9 { 10 public: 11 string reverseString(string s) 12 { 13 int len=s.length(); 14 int i=0,j=len-1; 15 char temp; 16 while(i<j) 17 { 18 temp=s[j]; 19 s[j--]=s[i]; 20 s[i++]=temp; 21 } 22 return s; 23 } 24 };
逆置字符串,首末指针,交换指针指向值即可。
浙公网安备 33010602011771号