본문 바로가기

0/leetcode

784. Letter Case Permutation

반응형

leetcode.com/problems/letter-case-permutation/

 

Letter Case Permutation - 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 letterCasePermutation(self, S: str) -> List[str]:
        
        output = [""]
        
        for i in range(len(S)) :
            
            curr = []
            
            for j in range(len(output)) :
                if S[i].isalpha() :
                    curr.append(output[j]+S[i].lower())
                    curr.append(output[j]+S[i].upper())
                else :
                    curr.append(output[j]+S[i])
                    
            output = curr
        
        return output
    

 

정리 :

항상 iterative한 방법으로 접근.

반응형

'0 > leetcode' 카테고리의 다른 글

134. Gas Station  (0) 2020.09.24
416. Partition Equal Subset Sum  (0) 2020.09.18
55. Jump Game  (0) 2020.09.09
207. Course Schedule  (0) 2020.09.08
41. First Missing Positive  (0) 2020.09.08