Skip to content

Commit bcef76f

Browse files
add LazerBeam solution
1 parent f37b6d3 commit bcef76f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

medium300/LaserBeam.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package medium300;
2+
3+
public class LaserBeam {
4+
5+
int gcd(int a, int b) {
6+
if (b == 0)
7+
return a;
8+
return gcd(b, a % b);
9+
}
10+
11+
public int calculateNumberOfEnteredCells(int x1, int y1, int x2, int y2) {
12+
13+
int a = Math.abs(x1 - x2);
14+
int b = Math.abs(y1 - y2);
15+
16+
return a + b - gcd(Math.max(a, b), Math.min(a, b));
17+
}
18+
19+
public static void main(String[] args) {
20+
LaserBeam l = new LaserBeam();
21+
System.out.println(l.calculateNumberOfEnteredCells(9333, 3923, 63958, 10065));
22+
}
23+
}

0 commit comments

Comments
 (0)