forked from SnowScriptWinterOfCode/LeetCode_Q
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Day 19-q1 python code added SnowScriptWinterOfCode#415
- Loading branch information
1 parent
f121f12
commit e9e1e73
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
Day-19/q1 Find Players With Zero or One Losses/Tech-neophyte--p.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## Python code: (Using dict) | ||
``` | ||
class Solution: | ||
def findWinners(self, matches: List[List[int]]) -> List[List[int]]: | ||
loss={} | ||
for p in matches: | ||
x, y=p | ||
if x not in loss: loss[x]=0 | ||
if y in loss: loss[y]+=1 | ||
else: loss[y]=1 | ||
ans=[[], []] | ||
for i, f in loss.items(): | ||
if f==0: | ||
ans[0].append(i) | ||
elif f==1: | ||
ans[1].append(i) | ||
return [sorted(ans[0]), sorted(ans[1])] | ||
``` |