> For the complete documentation index, see [llms.txt](https://simian114.gitbook.io/blog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://simian114.gitbook.io/blog/undefined/undefined-1/02.-leetcode-344.md).

# 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()
```
