문제 링크: https://leetcode.com/problems/reverse-string/
주어진 문자열들을 역순으로 정렬하면 되는 문제이다.
유의할 점은
You must do this by modifying the input array in-place with O(1) extra memory.
O(1)의 메모리를 활용하여 풀어야한다.
그리고 방법중에 투포인터를 이용하여 푸는 방법이 있었다.
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
start = 0
end = len(s) -1
while start<end:
s[start], s[end] = s[end], s[start]
start +=1
end -= 1
많이 어려운 문제는 아니었다
Runtime: 304 ms, faster than 29.08% of Python3 online submissions for Reverse String.
Memory Usage: 18.4 MB, less than 45.83% of Python3 online submissions for Reverse String.