Skip to main content

1996 - The Number of Weak Characters in the Game

Details

KeyValue
Linkhttps://leetcode.com/problems/the-number-of-weak-characters-in-the-game/
LanguagePython 3
Runtime4969 ms, faster than 6.75% of Python3 online submissions for The Number of Weak Characters in the Game
Memory Usage67 MB, less than 79.12% of Python3 online submissions for The Number of Weak Characters in the Game
DatastructuresList[List[int]]
AlgorithmsSort + Greedy
ComplexityTime: O(NlogN) Memory: O(N)

Procedure

  1. ...

Code

class Solution:
def numberOfWeakCharacters(self, properties: List[List[int]]) -> int:
number_of_weak_characters = max_defense = 0

properties.sort(key = lambda x : (-x[0],x[1]))

for attack, defense in properties:
if defense < max_defense: number_of_weak_characters += 1
max_defense = max(max_defense, defense)

return number_of_weak_characters