[LeetCode][344. Reverse String] 2 Approaches: Two Pointers and Recursion
By Long Luo
This article is the solution 2 Approaches: Two Pointers and Recursion of Problem 344. Reverse String .
Here shows 2 Approaches to slove this problem, Recursion and Two Pointers.
Two Pointers
Most of us may think about two pointers solution.
We need
1 | public void reverseString(char[] s) { |
or use For Loop:
1 | // Two Pointers Opt O(n) O(1) |
Analysis
- Time Complexity:
- Space Complexity:
Recursion
Recursive solution is also easy.
1 | public void reverseString(char[] s) { |
Analysis
- Time Complexity:
- Space Complexity:
All suggestions are welcome. If you have any query or suggestion please comment below. Please upvote👍 if you like💗 it. Thank you:-)
Explore More Leetcode Solutions. 😉😃💗
预览: