Problem · String
Reverse a String
Learn this problemProblem statement
Given a string s, return a new string containing the same characters in reverse order.
Preserve character case, spaces, digits, and punctuation. An empty input returns an empty string.
Function
reverseString(s: String) → StringExamples
Example 1
s = "FastPrep"return = "perPtsaF"Reading FastPrep from right to left produces perPtsaF.
Example 2
s = "a b!"return = "!b a"The punctuation and space remain characters and move to their reversed positions.
Example 3
s = ""return = ""The reverse of the empty string is the empty string.
Constraints
0 <= s.length <= 200000scontains only printable ASCII characters.