본문 바로가기

두두의 알고리즘/문제

[기타] 릿코드 Easy 344 'Reverse String' (Python)

728x90

<문제 링크>

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


<문제 풀이>

  1. 문자열 길이의 반만큼 양 쪽 문자를 스와프 해주면 됨

<코드>

class Solution:
    def reverseString(self, s: List[str]) -> None:
        """
        Do not return anything, modify s in-place instead.
        """
        for i in range(len(s)//2):
            s[i], s[len(s)-1-i] = s[len(s)-1-i], s[i]