반응형
문제 링크 : 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
책 문자열 중 두번째 문제. 가장 쉽다.
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
s[:] = s[::-1]
책에 쓰여있듯이 s = s[::-1]
은 reference가 변경되서 에러가 난다. s[:] = s[::-1]
로 value만 변경해야한다.