Skip to content

344. Reverse String

Edited by Charles

Easy · Python · String

Problem

Read the original problem on LeetCode.

The official page contains the problem statement, examples, and constraints.

Explanation, examples & other approaches

Core idea

The input is a list. Double pointers is the source code idea of built-in function reverse.

Original study notes follow, including intermediate snippets and earlier attempts.

Note:

  1. The input is a list.
  2. Double pointers is the source code idea of built-in function reverse.
  3. In Python we can also use [::-1] to reverse.
Study record
Field Value
Attempts 1
Mastery ❚
The Latest Attempt January 6, 2026

Python solution

class Solution:
    def reverseString(self, s: List[str]) -> None:
        """
        Do not return anything, modify s in-place instead.
        """
        # s[:] = s[::-1]
        left, right = 0, len(s) - 1

        while left < right:
            s[left], s[right] = s[right], s[left]
            left += 1
            right -= 1

Back to Day 7 String I · All Algorithm notes