Skip to content

Commit

Permalink
2024-02-24 solved
Browse files Browse the repository at this point in the history
  • Loading branch information
alstjr7437 committed Feb 24, 2024
1 parent 6814e07 commit 42f8af8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions alstjr7437/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
| 8차시 | 2024.02.14 | DP | <a href="https://www.acmicpc.net/problem/12865">평범한 배낭</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/24 |
| 9차시 | 2024.02.17 | 그리디 | <a href="https://www.acmicpc.net/problem/2138">전구와 스위치</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/29 |
| 10차시 | 2024.02.20 | BFS/DFS | <a href="https://www.acmicpc.net/problem/11725">트리의 부모 찾기</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/33 |
| 11차시 | 2024.02.23 | 해시 | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/42579">베스트 앨범</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/39 |

2 changes: 1 addition & 1 deletion alstjr7437/트리/트리의-부모-찾기.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ def bfs():
bfs()

for i in range(2, n+1):
print(visited[i])
print(visited[i])
30 changes: 30 additions & 0 deletions alstjr7437/해시/베스트앨범.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
def solution(genres, plays):
answer = []
dict = {}

# 딕셔너리 만들기
for i in range(len(genres)):
if genres[i] not in dict :
dict[genres[i]] = [[plays[i], i]]
else :
dict[genres[i]].append([plays[i],i])

# 딕셔너리 안에 재생회수로 재정렬
for genres, plays in dict.items():
dict[genres] = sorted(plays, key=lambda x: x[0], reverse=True)

# 각 장르 총합 계산
totals = {i: sum(j[0] for j in songs) for i, songs in dict.items()}

# 총합 기준으로 딕셔너리 순서 변경
sorted_data = {k: v for k, v in sorted(dict.items(), key=lambda item: totals[item[0]], reverse=True)}


# 정답 인덱스 추가 부분
for i in sorted_data.values():
answer.append(i[0][1])
if len(i) != 1:
answer.append(i[1][1])


return answer

0 comments on commit 42f8af8

Please sign in to comment.