首页 > TAG信息列表 > ReverseString
344. 反转字符串
class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead. """ i = 0 j = len(s) - 1 while i < j:字符串逆置
#include <iostream>#include <string>#include <algorithm> using namespace std; void reverseString(string &s){ int i, j; for (i = 0, j = s.size() - 1; i < j; ++i, --j) { swap(s[i], s[j]); }} int main(){ string str; while(cin>>反转字符串 Java
力扣题目链接 位运算 class Solution { public void reverseString(char[] s) { int l = 0; int r = s.length - 1; while(l<r){ s[l] ^= s[r];//s[l] = a^b s[r] ^= s[l];//s[r] = b^a^b = a; s[l] ^= s[r];//s