Reverse a String
Problem statement
Return the characters of s in reverse order. Preserve spaces, punctuation, letter case and repeated characters. The empty string reverses to itself.
Function
reverseString(s: String) → StringExamples
Example 1
s = "AMD"return = "DMA"Reading indices 2, 1 and 0 yields D, M and A.
Example 2
s = "a b!"return = "!b a"The final exclamation mark becomes first, and the space is preserved.
Constraints
0 <= s.length <= 2000.- Every character is printable ASCII with a code from 32 through 126.