Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- MySQL
- 단어 수학
- 수 만들기
- 탄막 스킬 범위
- c#
- 알고리즘
- 원형
- 탄막 이동
- 유니티
- mysqld.sock
- 회의실 배정
- 자료구조 목차
- 알고리즘 목차
- 탄막
- 2020 KAKAO BLIND RECRUITMENT
- 윈도우
- 영상 프레임 추출
- 토글 그룹
- 강의실2
- 3273
- 3344
- 걷는건귀찮아
- 그리디알고리즘
- AI Hub
- 마우스 따라다니기
- 우분투
- 문자열 압축
- 백준
- 18249
- SWEA
Archives
- Today
- Total
와이유스토리
[문자열] 프로그래머스 후보키 Python 본문
https://programmers.co.kr/learn/courses/30/lessons/42890
코딩테스트 연습 - 후보키
[["100","ryan","music","2"],["200","apeach","math","2"],["300","tube","computer","3"],["400","con","computer","4"],["500","muzi","music","3"],["600","apeach","music","2"]] 2
programmers.co.kr
from itertools import combinations
def solution(relation):
row = len(relation)
col = len(relation[0])
comb = []
for s in range(1, col+1):
comb+=combinations(range(col), s) # 열 조합 생성
# 유일성
li = []
for c in comb:
temp = [tuple([item[i] for i in c]) for item in relation] # 중요
if len(set(temp)) == row:
li.append(c) # + = append != join != extend
# 최소성
answer = set(li) # {}
for i in range(len(answer)):
for j in range(i+1, len(li)):
if len(li[i]) == len(set(li[i]) & set(li[j])): # 교집합
answer.discard(li[j])
return len(answer)
from itertools import combinations
def solution(relation):
row = len(relation)
col = len(relation[0])
comb = []
for s in range(1, col+1):
comb+=combinations(range(col), s) # 열 조합 생성
# 유일성
li = []
for c in comb:
temp = []
for item in relation:
a = []
for i in c:
a.append(item[i])
temp.append(tuple(a))
if len(set(temp)) == row:
li.append(c) # append != join != extend
# 최소성
answer = set(li) # {}
for i in range(len(answer)):
for j in range(i+1, len(li)):
if len(li[i]) == len(set(li[i]) & set(li[j])): # 교집합
answer.discard(li[j])
return len(answer)
'코딩테스트 > 문자열' 카테고리의 다른 글
[문자열] 프로그래머스 개인정보 수집 유효기간 C++, Python (0) | 2023.01.18 |
---|---|
[문자열] 프로그래머스 시저 암호 Java (0) | 2022.12.16 |
[문자열, 이진탐색] 프로그래머스 순위 검색 Python (0) | 2022.02.04 |
[딕셔너리] 프로그래머스 오픈채팅방 Python (0) | 2022.02.04 |
[문자열] 프로그래머스 [1차] 뉴스 클러스터링 Python (0) | 2022.02.04 |
Comments