Algorithm/Python

[LeetCode] 344. Reverse String

🥭맹2 2021. 6. 1. 21:58

1. 문제

https://leetcode.com/problems/reverse-string

 

Reverse String - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

2. 접근 방법

문자열 뒤짚기인데, 슬라이싱 사용해서 s[::-1]이렇게 풀ㄹ면 안된다..

왜냐면

공간 복잡도를 O(1)로 제한 했기 때무니다 ...

깐깐해

그래서 reverse()를 사용해따

3. 코드

python

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

4. 마치며

영어와 친해져보쟈

'Algorithm > Python' 카테고리의 다른 글

[LeetCode] 49. Group Anagrams  (3) 2021.06.03
[LeetCode] 937. Reorder Log Files  (2) 2021.06.02
[LeetCode] 125. Valid Palindrome  (0) 2021.06.01
[백준 1759] 암호만들기  (1) 2021.05.27
[백준 11723] 집합  (1) 2021.05.26