LeetCode Entry
344. Reverse String
Reverse an array
344. Reverse String easy
blog post
substack
youtube

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/626
Problem TLDR
Reverse an array #easy
Intuition
We can use two pointers or just a single for-loop until the middle.
Approach
- Careful with the corner case: exclude the middle for the even size
- try to use built-in functions
Complexity
-
Time complexity: \(O(n)\)
-
Space complexity: \(O(1)\)
Code
fun reverseString(s: CharArray) = s.reverse()
pub fn reverse_string(s: &mut Vec<char>) {
s.reverse()
}