Welcome to my world!
Difficulty: Easy
Tags: Two Pointers, String
反转字符串。
直接反转。
▷ Time Complexity: O(n)
▷ Space Complexity: O(1)
1234567891011121314
class Solution {public: string reverseString(string s) { int length = s.size(); int iter = length/2; for(int i=0; i<iter; i++){ char t = s[i]; s[i] = s[length-1-i]; s[length-1-i] = t; } return s; }};
回到 Conquer Leetcode