Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 매일메일
- JavaScript
- sw expert academy
- react-router
- createSlice
- 테코테코
- useDispatch
- 리액트
- 프로그래머스
- C++
- SW
- redux
- Algorithm
- redux-saga
- axios
- java
- Get
- json-server
- 코딩테스트합격자되기
- 이코테
- Python
- programmers
- 항해99
- redux-toolkit
- react
- 자바
- 알고리즘
- maeil-mail
- react-redux
- 항해플러스
Archives
- Today
- Total
Binary Journey
[프로그래머스] 순위 본문
반응형
출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges
** 시도중
from collections import deque
def solution(n, results):
win_graph = [ [] for i in range(n + 1) ]
lose_graph = [ [] for i in range(n + 1) ]
wn_c = [ 0 for i in range(n + 1) ]
for result in results:
win_graph[result[0]].append(result[1])
lose_graph[result[1]].append(result[0])
queue = deque()
queue.append(results[0][0])
answer = 0
print(win_graph)
print(lose_graph)
while queue:
now = queue.popleft()
print(now)
for loser in win_graph[now]:
if wn_c[loser] == 0:
queue.append(loser)
wn_c[loser] -= 1
print(wn_c)
return answer
def solution(n, results):
wins, loses = {}, {}
for i in range(1, n+1):
wins[i], loses[i] = set(), set()
for i in range(1, n+1):
for r in results:
if r[0] == i:
wins[i].add(r[1])
if r[1] == i:
loses[i].add(r[0])
# i번째 사람을 이겼던 사람들에게 i번째 사람이 이겼던 사람 추가
for winner in loses[i]:
wins[winner].update(wins[i])
# i번째 사람에게 진 사람들에게 i번째 사람이 졌던 사람 추가
for loser in wins[i]:
loses[loser].update(loses[i])
cnt = 0
for i in range(1, n+1):
if len(wins[i]) + len(loses[i]) == n-1:
cnt += 1
return cnt
참고: https://bladejun.tistory.com/111
반응형
'프로그래머스 > level 3' 카테고리의 다른 글
[프로그래머스] 이중우선순위큐 (0) | 2022.06.23 |
---|---|
[프로그래머스] 베스트 앨범 (0) | 2022.05.20 |
[프로그래머스] 가장 먼 노드 (0) | 2022.04.21 |
[프로그래머스] 정수 삼각형 (0) | 2022.03.16 |
[프로그래머스] 헤비 유저가 소유한 장소 (MySQL) (0) | 2021.08.10 |