String Reverse
easySave
StringTwo Pointers
Given a string, return the string reversed. You should implement a function that reverses the string without using any built-in reverse functions.
Example 1
Input
[ "hello" ]
Output
olleh
Explanation. The string 'hello' reversed is 'olleh'.
Example 2
Input
[ "12345" ]
Output
54321
Explanation. Reversing the digits '12345' gives '54321'.
Example 3
Input
[ "racecar" ]
Output
racecar
Explanation. The string 'racecar' is a palindrome and remains the same when reversed.
Example 4
Input
[ "!@#$%^" ]
Output
^%$#@!
Explanation. Special characters are reversed just like alphabetic characters.
Follow-up: How would you handle strings that include unicode characters such as emojis or characters from non-Latin scripts?
Constraints:
The input string will not be empty and will consist of printable ASCII characters only.
- Views
- 3