# 02. 문자열 뒤집기(leetcode: 344)

두 가지 풀이법이 있다.

1. 투 포인터 기법을 사용해서 앞뒤를 바꾸는 것
2. 파이썬 문자열 메서드를 사용해서 바로 뒤집어 버리는 방법

### 투 포인터

Left, right 라는 포인터를 만들고 각각 문자열의 시작, 끝 인덱스를 할당해 준다. 이후로는 앞과 뒤를 바로 스왑해주는 방식으로 진행하면 됨.

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

### reverse 메서드

파이썬 문자열 메서드 중에는 `reverse` 가 있다. 따라서 이 한줄만 사용하면 문제 해결!

```python
class Solution:
    def reverseString(self, s: List[str]) -> None:
        """
        Do not return anything, modify s in-place instead.
        """
        return s.reverse()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://simian114.gitbook.io/blog/undefined/undefined-1/02.-leetcode-344.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
