Digking's cave

LeetCode 리트코드 ) Reverse String (Python) 본문

코딩테스트/알고리즘

LeetCode 리트코드 ) Reverse String (Python)

디깅 2022. 7. 25. 17:46
728x90

https://leetcode.com/explore/learn/card/array-and-string/205/array-two-pointer-technique/1183/

 

Explore - LeetCode

LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore.

leetcode.com

 

문제

 

풀이

class Solution:
    def reverseString(self, s: List[str]) -> None:
        """
        Do not return anything, modify s in-place instead.
        """
        leftnum, rightnum = 0 , len(s)-1
        
        while (leftnum < rightnum ):
            s[leftnum],s[rightnum] = s[rightnum],s[leftnum]
            leftnum += 1
            rightnum -= 1
            
            
            
# 추가 풀이
class Solution:
    def reverseString(self, s: List[str]) -> None:
        s.reverse()
반응형