789. Escape The Ghosts
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 63% Topics: Array, Math
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def escapeGhosts(self, ghosts, target):
"""
:type ghosts: List[List[int]]
:type target: List[int]
:rtype: bool
"""
total = abs(target[0])+abs(target[1])
return all(total < abs(target[0]-i)+abs(target[1]-j) for i, j in ghosts)
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions