-
Notifications
You must be signed in to change notification settings - Fork 2
문제 020 : 완주하지 못한 선수 #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: solutions
Are you sure you want to change the base?
Conversation
👋 @tiaz0128 님 안녕하세요! 08장 해시
|
🎉 @tiaz0128 님. 축하 합니다! 문제 도움이 필요한 사람들이 있으면 도와주세요! 소통하면서 더 성장 할 수 있는 좋은 기회입니다! |
✨ 아래의 코드는 테스트를 통과한 코드입니다. def solution(participant, completion):
a = {part: 0 for part in participant}
for x in participant:
a[x] += 1
for x in completion:
a[x] -= 1
return [x for x in a if a[x] != 0][0] |
🎉 @tiaz0128 님. 축하 합니다! 문제 도움이 필요한 사람들이 있으면 도와주세요! 소통하면서 더 성장 할 수 있는 좋은 기회입니다! |
✨ 아래의 코드는 테스트를 통과한 코드입니다. from collections import Counter
def solution(participant, completion):
return list(Counter(participant) - Counter(completion))[0] |
from collections import Counter
# 리스트 내 요소의 개수 세기
elements = ['red', 'blue', 'red', 'green', 'blue', 'blue']
counter = Counter(elements)
print(counter) # 결과: Counter({'blue': 3, 'red': 2, 'green': 1}) |
Counter 객체의 주요 메소드와 사용법
# 가장 흔한 요소 찾기
most_common_element = counter.most_common(1)
print(most_common_element) # 결과: [('blue', 3)]
# 요소 추가하기
counter.update(['red', 'yellow'])
print(counter) # 결과: Counter({'blue': 3, 'red': 3, 'green': 1, 'yellow': 1})
# 요소 빼기
counter.subtract(['red'])
print(counter) # 결과: Counter({'blue': 3, 'red': 2, 'green': 1, 'yellow': 1})
# 요소의 개수 직접 변경하기
counter['blue'] = 1
print(counter) # 결과: Counter({'red': 2, 'blue': 1, 'green': 1, 'yellow': 1})
# 요소의 개수 가져오기
print(counter['red']) # 결과: 2
# 존재하지 않는 요소의 개수 가져오기
print(counter['purple']) # 결과: 0 |
소요시간
사용한 자료구조, 알고리즘
해당 자료구조, 알고리즘을 사용한 근거
어려웠던 구현 포인트
collections
에서Counter
라는 아주 유용한 내장 클래스가 있다는 걸 배움구현한 코드의 시간 복잡도
추가한 테스트 케이스와 그 이유
개선이 필요한 부분은?
collections
에서Counter
라는 아주 유용한 내장 클래스가 있다