Skip to content

Commit 4b43ccd

Browse files
committed
weekly contest 362
problem 2
1 parent 9593da6 commit 4b43ccd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.longluo.contest.weekly_contest_362;
2+
3+
/**
4+
* https://leetcode.cn/contest/weekly-contest-362
5+
*/
6+
public class Problem2 {
7+
8+
public static boolean isReachableAtTime(int sx, int sy, int fx, int fy, int t) {
9+
int x = Math.abs(fx - sx);
10+
int y = Math.abs(fy - sy);
11+
12+
int min = Math.max(x, y);
13+
14+
if (min == 0) {
15+
return t != 1;
16+
}
17+
18+
return t >= min;
19+
}
20+
21+
public static void main(String[] args) {
22+
System.out.println("true ?= " + isReachableAtTime(2, 4, 7, 7, 6));
23+
System.out.println("false ?= " + isReachableAtTime(3, 1, 7, 3, 3));
24+
System.out.println("true ?= " + isReachableAtTime(1, 1, 1, 3, 2));
25+
System.out.println("false ?= " + isReachableAtTime(1, 2, 1, 2, 1));
26+
}
27+
}

0 commit comments

Comments
 (0)