Leetcode Problem 789. Escape The Ghosts
789. Escape The Ghosts
AI Mock Interview
Leetcode Solutions
Taxicab Distance Comparison
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Calculate the taxicab distance from the player's starting point
[0, 0]
to the target
[xtarget, ytarget]
.
For each ghost in the
ghosts
array, calculate the taxicab distance from the ghost's starting point to the target.
If any ghost's distance to the target is less than or equal to the player's distance to the target, return
false
as the player cannot escape.
If all ghosts have a greater distance to the target than the player, return
true
as the player can escape.
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...