diff options
author | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
---|---|---|
committer | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
commit | d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa (patch) | |
tree | 96df922dae2a5073d9a50ea70c7aae6aa37e3ebe /find_players_zero_loss.py | |
download | leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.tar.gz leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.zip |
initial
Diffstat (limited to 'find_players_zero_loss.py')
-rw-r--r-- | find_players_zero_loss.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/find_players_zero_loss.py b/find_players_zero_loss.py new file mode 100644 index 0000000..428e306 --- /dev/null +++ b/find_players_zero_loss.py @@ -0,0 +1,49 @@ +# 2225. Find Players With Zero or One Losses + +""" +given an integer array 'matches' where 'matches[i] = [winner[i], loser[i]]' +indicates a defeated player 'loser[i]' 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. +""" + + +class Solution(object): + def findWinners(self, matches): + """ + :type matches: List[List[int]] + :rtype: List[List[int]] + """ + losses = [0] * 100001 + for winner, loser in matches: + if losses[winner] == 0: + losses[winner] = -1 + if losses[loser] == -1: + losses[loser] = 1 + else: + losses[loser] += 1 + zero_loss = [i for i in range(1, 100001) if losses[i] == -1] + one_loss = [i for i in range(1, 100001) if losses[i] == 1] + return [zero_loss, one_loss] + + +if __name__ == "__main__": + obj = Solution() + print( + obj.findWinners( + matches=[ + [1, 3], + [2, 3], + [3, 6], + [5, 6], + [5, 7], + [4, 5], + [4, 8], + [4, 9], + [10, 4], + [10, 9], + ] + ) + ) + print(obj.findWinners(matches=[[2, 3], [1, 3], [5, 4], [6, 4]])) |