Leetcode Problem 789. Escape The Ghosts

789. Escape The Ghosts

Leetcode Solutions

Taxicab Distance Comparison

  1. Calculate the taxicab distance from the player's starting point [0, 0] to the target [xtarget, ytarget].
  2. For each ghost in the ghosts array, calculate the taxicab distance from the ghost's starting point to the target.
  3. 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.
  4. If all ghosts have a greater distance to the target than the player, return true as the player can escape.
UML Thumbnail

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...