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 | 29 | 30 | 31 |
Tags
- python 릿코드
- leetcode풀이
- LeetCode
- 파이썬 알고리즘
- 릿코드
- 파이썬알고리즘풀기
- 파이썬릿코드
- 알고리즘풀이
- python xor
- 릿코드 풀기
- leetcode 풀기
- 릿코드 파이썬
- binary search
- python zip_longest
- leetcode풀기
- 잇츠디모
- 파이썬 릿코드
- 코틀린기초
- python sorted
- 파이썬알고리즘
- 파이썬 프로그래머스
- python priority queue
- 상가수익률계산기
- 알고리즘풀기
- 릿코드풀이
- 파이썬릿코드풀기
- python 알고리즘
- python Leetcode
- 릿코드풀기
- 파이썬 알고리즘 풀기
Archives
- Today
- Total
소프트웨어에 대한 모든 것
2225. Find Players With Zero or One Losses 본문
반응형
문제)
2225. Find Players With Zero or One Losses
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.
Thus, answer[0] = [1,2,10] and answer[1] = [4,5,7,8].
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.
Thus, answer[0] = [1,2,5,6] and answer[1] = [].
Constraints:
- 1 <= matches.length <= 105
- matches[i].length == 2
- 1 <= winneri, loseri <= 105
- winneri != loseri
- All matches[i] are unique.
문제 이해)
- 위너, 루저를 분리
- counter, set 사용
솔루션1)
class Solution:
def findWinners(self, matches: List[List[int]]) -> List[List[int]]:
# 위너, 루저 분리
matches = (list(zip(*matches)))
winners = matches[0]
loser = matches[1]
# 한 번만 패배한 루저 찾기
loser_counter = Counter(loser)
answer2 = [n for n, count in loser_counter.items() if count == 1]
# 한 번도 패배하지 않은 위너 찾기
winners = set(winners) - set(loser_counter)
return [sorted(winners), sorted(answer2)]
반응형
'알고리즘 > LeetCode' 카테고리의 다른 글
150. Evaluate Reverse Polish Notation (0) | 2022.12.17 |
---|---|
1209. Remove All Adjacent Duplicates in String II (0) | 2022.12.15 |
451. Sort Characters By Frequency (0) | 2022.12.14 |
1704. Determine if String Halves Are Alike (0) | 2022.12.14 |
931. Minimum Falling Path Sum (0) | 2022.12.13 |
Comments