GitHub - 4074/leetcode-helper: A chrome extension helps you have fun at leetcode.com and leetcode-cn.com
Click the Copy button on the right side, the question will be copyed for markdown.
# [344\. Reverse String](https://leetcode.com/problems/reverse-string/) ## Description Difficulty: **Easy** Related Topics: [Two Pointers](https://leetcode.com/tag/two-pointers/), [String](https://leetcode.com/tag/string/), [Recursion](https://leetcode.com/tag/recursion/) Write a function that reverses a string. The input string is given as an array of characters `s`. You must do this by modifying the input array with `O(1)` extra memory. **Example 1:** \``` Input: s = ["h","e","l","l","o"] Output: ["o","l","l","e","h"] \``` **Example 2:** \``` Input: s = ["H","a","n","n","a","h"] Output: ["h","a","n","n","a","H"] \``` **Constraints:** * 1 <= s.length <= 10<sup>5</sup> * `s[i]` is a . ## Solution Language: **JavaScript** \```javascript /** * @param {string} s * @return {string} */ var reverseString = function(s) { return s.split('').reverse().join(''); }; \```
Then, open a problem page in leetcode, you would see the buttons.