최대 1 분 소요

문제링크

from itertools import combinations

def solution(relation):
    row = len(relation)
    col = len(relation[0])

    combo = []
    for i in range(1, col+1):
        combo.extend(combinations(range(col), i))
        
    unique = []
    for i in combo:
        tmp = [tuple([item[key] for key in i]) for item in relation]

        if len(set(tmp)) == row:  
            put = True
            
            for x in unique:
                if set(x).issubset(set(i)):
                    put = False
                    break
                    
            if put: unique.append(i)
    return len(unique)

https://velog.io/@sem/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-LEVEL2-%ED%9B%84%EB%B3%B4%ED%82%A4-Python

댓글남기기