
https://programmers.co.kr/learn/courses/30/lessons/17677
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr




Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
def solution(str1, str2): | |
set1 = [] | |
set2 = [] | |
for i in range(1, len(str1)): | |
if str1[i-1:i+1].isalpha(): | |
set1.append(str1[i-1:i+1].lower()) | |
for i in range(1, len(str2)): | |
if str2[i-1:i+1].isalpha(): | |
set2.append(str2[i-1:i+1].lower()) | |
counter1 = Counter(set1) | |
counter2 = Counter(set2) | |
intersection = counter1 & counter2 | |
union = counter1 | counter2 | |
if not intersection: | |
if not union: | |
return 65536 | |
else: | |
return 0 | |
i, u = 0, 0 | |
for e, v in intersection.items(): | |
i += v | |
for e, v in union.items(): | |
u += v | |
return int((i/u)*65536) |
collections 모듈의 Counter를 썼는데, 다른 분들의 풀이를 보니까 안써도 풀 수 있는 것 같다.
기존 집합에서는 문제에서 요구하는 다중 집합을 처리 못할 줄 알았는데 가능한가보다.
머리가 나쁘면 몸이 고생하는 법^_^!
'Algorithm > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 압축 / Python / 2018 KAKAO BLIND RECRUITMENT (0) | 2020.04.21 |
---|---|
[프로그래머스] 프렌즈4블록 / Python / 2018 KAKAO BLIND RECRUITMENT (0) | 2020.04.19 |
[프로그래머스] 괄호 변환 / Python / 2020 KAKAO BLIND RECRUITMENT (0) | 2020.04.15 |
[프로그래머스] 문자열 압축 / Python / 2020 KAKAO BLIND RECRUITMENT (0) | 2020.04.15 |
[프로그래머스] 셔틀 버스 / Python / 2018 KAKAO BLIND RECRUITMENT (0) | 2020.04.15 |
,