-
Notifications
You must be signed in to change notification settings - Fork 2
[WEEK1 이수연] 해시 및 정렬 리뷰 #3
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
Open
2SOOY
wants to merge
1
commit into
master
Choose a base branch
from
sooyeon_week1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # 풀이 1 - Counter 이용 | ||
| from collections import Counter | ||
|
|
||
| def solution(participant, completion): | ||
| # Counter를 이용하면 리스트 내의 성분의 숫자를 딕셔너리 형태로 반환해준다 | ||
| # ex) list1 =['a', 'b', 'c', 'a'] => Counter(list1) : {'a':2, 'b':1, 'c':1} | ||
| not_completion = Counter(participant) - Counter(completion) # Counter의 경우 사칙연산도 가능 | ||
|
|
||
| return list(not_completion.keys())[0] | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # 시간복잡도 O(n^2) | ||
|
|
||
| def solution(phone_book): | ||
| # phone_book 전체를 반복 => 기준 설정 | ||
| for phone_num in phone_book: | ||
| # 반복문을 통해 나머지 번호들과 비교 | ||
| for compare_num in phone_book: | ||
| if phone_num == compare_num: | ||
| continue | ||
| # 접두어 확인 | ||
| # ex) '119','1195524421' 비교 | ||
| # '1195524421'에서 '119'길이(3) 원소까지만 비교 | ||
| if phone_num in compare_num[:len(phone_num)]: | ||
| return False | ||
|
|
||
| return True |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| def solution(clothes): | ||
| # 1. 주어진 정보를 바탕으로 자료 구성 | ||
| clothes_info = {} # 의상 타입(key): 의상 수(value) | ||
| for c_name, c_type in clothes: | ||
| clothes_info[c_type] = clothes_info.get(c_type, 0) + 1 | ||
|
|
||
| # 2. 경우의 수 구하기 | ||
| result = 1 # 조합 가능한 경우의 수 | ||
| # a1, a2, a3, b1, b2 의상이 존재할 때 경우의 수 | ||
| # (3 + 1) * (2 + 1) - 1 | ||
| # +1의 이유는 착용을 안하는 경우 | ||
| # 마지막 -1의 경우는 문제에서 제시된 최소 하나는 착용한다 | ||
| for value in clothes_info.values(): | ||
| result *= value + 1 | ||
|
|
||
| return result - 1 |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| def solution(genres, plays): | ||
| GEN, PLAY = 0, 1 # 장르, 재생횟수 | ||
| VALUE = 1 # 딕셔너리에서 value의 인덱스 | ||
|
|
||
| # 1. 주어진 정보 배열들을 알맞게 조작하기 | ||
| song_info = [(gen, play) for gen, play in zip(genres, plays)] | ||
|
|
||
| dic_songs = {} # 장르(key): 노래정보(고유번호, 재생횟수) | ||
| dic_plays = {} # 장르(key): 재생횟수 합 | ||
| for idx, info in enumerate(song_info): | ||
| dic_songs[info[GEN]] = dic_songs.get(info[GEN], []) + [(idx, info[PLAY])] | ||
| dic_plays[info[GEN]] = dic_plays.get(info[GEN], 0) + info[PLAY] | ||
|
|
||
|
|
||
| # 2. 장르별 재생횟수 합이 높은 순서대로 정렬 | ||
| dic_plays = sorted(dic_plays.items(), key=lambda x: x[VALUE], reverse=True) | ||
|
|
||
|
|
||
| result = [] # 정답 배열 | ||
|
|
||
| # 3. 2단계에서 구한 정보를 바탕으로 각 장르에서 재생횟수가 높은 2가지 음악 번호 배열에 담기 | ||
| for gen, plays in dic_plays: | ||
| best_songs = dic_songs.get(gen) # best_songs = [(고유번호, 재생횟수), ...] | ||
| best_songs = sorted(best_songs, key=lambda x: x[PLAY], reverse=True) | ||
| if len(best_songs) >= 2 : # 해당 장르의 곡이 2개 이상일 경우 | ||
| for idx in range(2): | ||
| result.append(best_songs[idx][0]) | ||
| else: # 2개보다 작으면 전부 다 넣어 | ||
| for idx in range(len(best_songs)): | ||
| result.append(best_songs[idx][0]) | ||
|
|
||
| return result |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Counter를 이용하는 방법이 굉장히 유용하군요 ! 💯