Notice
Recent Posts
Recent Comments
«   2024/05   »
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 31
Tags
more
Archives
Today
Total
관리 메뉴

CHIqueen

[Intro] commonCharacterCount 본문

프로그래밍/CodeSignal

[Intro] commonCharacterCount

CHIqueen 2020. 3. 11. 13:18
from collections import Counter

def commonCharacterCount(s1, s2):
    common_letters = Counter(s1) & Counter(s2)
    return sum(common_letters.values())

딱히 Counter말고 떠오르는게 없어서 Counter를 썼다. 

def commonCharacterCount(s1, s2):
    com = [min(s1.count(i),s2.count(i)) for i in set(s1)]
    return sum(com)

다른 풀이를 보면 set으로 중복을 없앤 다음 파이썬 str 메서드중 count를 이용해 갯수를세 가장 최소를 구했다.

'프로그래밍 > CodeSignal' 카테고리의 다른 글

[Intro] Sort by Height  (0) 2020.03.11
[Intro] isLucky  (0) 2020.03.11
[Intro] All Longest Strings  (0) 2020.03.11
[Intro] matrixElementsSum  (0) 2020.03.11
[Intro] shapeArea  (0) 2020.03.03
Comments