Back to problems Sign in to unlock
Leetcode
Easy
Strings
Arrays
Reverse String
Reverse the characters of a string or character array in place.
Acceptance 0%
Problem Statement
Problem
Given a sequence of characters, reverse the order of the characters in place.
You should modify the input character array directly using only extra space.
Notes
- The input is typically provided as a mutable array of characters.
- The order of all characters must be reversed.
- No new array should be used for the main solution.
Input Format
- A mutable array of characters
s. - The array may be empty.
Output Format
- Modify
sin place so that its characters appear in reverse order.
Constraints
- Use extra space.
- A linear-time solution is expected.
Examples
Sample cases returned by the problem API.
Example 1
Input
s = ['h','e','l','l','o']
Output
['o','l','l','e','h']
Explanation
Swap the first and last characters, then continue inward until the pointers meet.
Example 2
Input
s = ['H','a','n','n','a','h']
Output
['h','a','n','n','a','H']
Explanation
Reversing the array places the last character first and the first character last.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.