엔지니어 게시판
LeetCode 솔루션 분류

# [11/28] 2225. Find Players With Zero or One Losses

• 작성
• 작성일

• 182 조회
• 1 댓글
• 0 추천
• 0 비추천

### 본문

You are given an integer array `matches` where `matches[i] = [winneri, loseri]` indicates that the player `winneri` defeated player `loseri` in a match.

Return a list `answer` of size `2` where:

• `answer[0]` is a list of all players that have not lost any matches.
• `answer[1]` is a list of all players that have lost exactly one match.

The values in the two lists should be returned in increasing order.

Note:

• You should only consider the players that have played at least one match.
• The testcases will be generated such that no two matches will have the same outcome.

Example 1:

```Input: matches = [[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]
Output: [[1,2,10],[4,5,7,8]]
Explanation:
Players 1, 2, and 10 have not lost any matches.
Players 4, 5, 7, and 8 each have lost one match.
Players 3, 6, and 9 each have lost two matches.
```

Example 2:

```Input: matches = [[2,3],[1,3],[5,4],[6,4]]
Output: [[1,2,5,6],[]]
Explanation:
Players 1, 2, 5, and 6 have not lost any matches.
Players 3 and 4 each have lost two matches.
```

Constraints:

• `1 <= matches.length <= 105`
• `matches[i].length == 2`
• `1 <= winneri, loseri <= 105`
• `winneri != loseri`
• All `matches[i]` are unique.
Accepted
69,948
Submissions
94,539
태그

댓글 1

## 학부유학생님의 댓글

• 익명
• 작성일
Runtime: 2493 ms, faster than 79.97% of Python3 online submissions for Find Players With Zero or One Losses.
Memory Usage: 70.4 MB, less than 10.26% of Python3 online submissions for Find Players With Zero or One Losses.
``````from collections import defaultdict
class Solution:
def findWinners(self, matches: List[List[int]]) -> List[List[int]]:
players = set()

res = [[],[]]

lost = defaultdict(int)

for winner, loser in matches:
lost[loser]+=1

for player in sorted(list(players)):
if player not in lost:
res[0].append(player)
elif lost[player] == 1:
res[1].append(player)

return res``````
전체 349 / 1 페이지

• 등록일 19:01
• 등록일 17:45
• 등록일 14:27
• 등록일 14:25
• 등록일 14:23
• 등록일 14:20
• 등록일 14:17
• 등록일 14:13
• 등록일 14:12
• 등록일 14:06
• 등록일 14:03
• 등록일 14:01

• 등록일 01.31
• 등록일 01.31
• 등록일 01.31
• 등록일 01.27
• 등록일 01.27
• 등록일 01.23
• 등록일 01.23

### Stats

• 현재 접속자 63 명
• 오늘 방문자 1,685 명
• 어제 방문자 1,866 명
• 최대 방문자 2,853 명
• 전체 회원수 535 명