LeetCode:Reverse String

Posted walker lee

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode:Reverse String相关的知识,希望对你有一定的参考价值。

Reverse String




Total Accepted: 32384 Total Submissions: 55169 Difficulty: Easy

Write a function that takes a string as input and returns the string reversed.

Example:
Given s = "hello", return "olleh".

Subscribe to see which companies asked this question

Hide Tags
 Two Pointers String
Hide Similar Problems
 (E) Reverse Vowels of a String
















c++ code:

class Solution {
public:
    string reverseString(string s) {
        
        int len = s.length();
        int i=0,j=len-1;
        
        while(i<j) {
            s[i] ^= s[j] ^= s[i] ^= s[j];
            i++;
            j--;
        }
        return s;
    }
};


以上是关于LeetCode:Reverse String的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode:Reverse String

LeetCode Reverse Vowels of a String

[LeetCode] Reverse String II

[leetcode] Reverse String II

[LeetCode] Reverse Words in a String II

LeetCode Reverse Words in a String III