题目

Escape The Ghosts

题解

The player can ensure escape if and only if he can reach the target before any ghost.

代码

class Solution:
    def escapeGhosts(self, ghosts: List[List[int]], target: List[int]) -> bool:
        player_distance = sum([abs(i) for i in target])
        for ghost_position in ghosts:
            ghost_distance = abs(
                ghost_position[0] - target[0]) + abs(ghost_position[1] - target[1])
            if ghost_distance <= player_distance:
                return False

        return True