[알고리즘/leetcode] Reverse String(python)

유현민·2022년 8월 17일
0

알고리즘

목록 보기
227/253

투포인터를 이용해서 문제를 풀었다.
왼쪽, 오른쪽 끝에서 각각 출발하여 바꾸면서 가운데까지 오면 된다.

class Solution:
    def reverseString(self, s: List[str]) -> None:
        """
        Do not return anything, modify s in-place instead.
        """
        l = len(s)
        if l > 1:
            f = 0
            e = l - 1
            while f < e:
                s[f], s[e] = s[e], s[f]
                f += 1
                e -= 1
profile
smilegate megaport infra

0개의 댓글