Fundamentals/Reverse String
← PrevNext →
Given a string s, return the string with its characters in reverse order.
Input
s: a string
Output
The reversed string.
Examples
Example 1
Inputs = "hello"
Outputolleh
Example 2
Inputs = "a"
Outputa
Constraints
Use two pointers from the ends moving toward the center, swapping characters.
Runs in O(n) time.