Skip to content

Commit 8f67406

Browse files
authored
Create find-players-with-zero-or-one-losses.py
1 parent b51dd25 commit 8f67406

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Time: O(nlogn)
2+
# Space: O(n)
3+
4+
import collections
5+
6+
7+
# hash, sort
8+
class Solution(object):
9+
def findWinners(self, matches):
10+
"""
11+
:type matches: List[List[int]]
12+
:rtype: List[List[int]]
13+
"""
14+
lose = collections.defaultdict(int)
15+
players_set = set()
16+
for x, y in matches:
17+
lose[y] += 1
18+
players_set.add(x)
19+
players_set.add(y)
20+
return [[x for x in sorted(players_set) if lose[x] == i] for i in xrange(2)]

0 commit comments

Comments
 (0)