Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 10. 24. 23:45

https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters/

 

Maximum Length of a Concatenated String with Unique Characters - 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 maxLength(self, arr: List[str]) -> int:
        uniq = []
        for s in arr:
            u = set(s)
            if len(u) == len(s):
                uniq.append(u)
        
        cc = [set()]
        for u in uniq:
            for c in cc:
                if not c & u:
                    cc.append(c|u)
        
        return max(len(ccc) for ccc in cc)
반응형