We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent afbf5db commit 1d10f51Copy full SHA for 1d10f51
Escape The Ghosts.java
@@ -0,0 +1,14 @@
1
+class Solution {
2
+ public boolean escapeGhosts(int[][] ghosts, int[] target) {
3
+ // explained as triangle inequality
4
+ // if ghost can reach target as fast as pacman,
5
+ // then it must can intercept pacman in the middle or at the end
6
+ // Just calculate if one path of ghost is <= path of pacman; Lost if so
7
+ int path = Math.abs(target[0]) + Math.abs(target[1]);
8
+ for(int[] ghost: ghosts) {
9
+ int pg = Math.abs(target[0] - ghost[0]) + Math.abs(target[1] - ghost[1]);
10
+ if(pg <= path) return false;
11
+ }
12
+ return true;
13
14
+}
0 commit comments