File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 280
280
| 1025 | [ Divisor Game] ( https://leetcode.com/problems/divisor-game ) | [ ![ Java] ( assets/java.png )] ( src/DivisorGame.java ) | |
281
281
| 1029 | [ Two City Scheduling] ( https://leetcode.com/problems/two-city-scheduling ) | | |
282
282
| 1030 | [ Matrix Cells in Distance Order] ( https://leetcode.com/problems/matrix-cells-in-distance-order ) | [ ![ Java] ( assets/java.png )] ( src/MatrixCellsInDistanceOrder.java ) | |
283
- | 1033 | [ Moving Stones Until Consecutive] ( https://leetcode.com/problems/moving-stones-until-consecutive ) | | |
283
+ | 1033 | [ Moving Stones Until Consecutive] ( https://leetcode.com/problems/moving-stones-until-consecutive ) | [ ![ Java ] ( assets/java.png )] ( src/ValidBoomerang.java ) | |
284
284
| 1037 | [ Valid Boomerang] ( https://leetcode.com/problems/valid-boomerang ) | | |
285
285
| 1042 | [ Flower Planting with no Adjacent] ( https://leetcode.com/problems/flower-planting-with-no-adjacent ) | | |
286
286
| 1046 | [ Last Stone Weight] ( https://leetcode.com/problems/last-stone-weight ) | | |
Original file line number Diff line number Diff line change
1
+ import java .util .Objects ;
2
+
3
+ public class ValidBoomerang {
4
+ public boolean isBoomerang (int [][] points ) {
5
+ Position p1 = Position .from (points [0 ]);
6
+ Position p2 = Position .from (points [1 ]);
7
+ Position p3 = Position .from (points [2 ]);
8
+ if (p1 .equals (p2 ) || p2 .equals (p3 ) || p3 .equals (p1 )) return false ;
9
+ if (p1 .x == p2 .x ) return p3 .x != p2 .x ;
10
+ if (p2 .x == p3 .x ) return true ;
11
+ return (p2 .y - p1 .y ) * (p3 .x - p2 .x ) != (p3 .y - p2 .y ) * (p2 .x - p1 .x );
12
+ }
13
+
14
+ private final static class Position {
15
+ private final int x ;
16
+ private final int y ;
17
+
18
+ private static Position from (int [] array ){
19
+ return new Position (array [0 ], array [1 ]);
20
+ }
21
+
22
+ Position (int x , int y ) {
23
+ this .x = x ;
24
+ this .y = y ;
25
+ }
26
+
27
+ @ Override
28
+ public boolean equals (Object o ) {
29
+ if (this == o ) return true ;
30
+ if (o == null || getClass () != o .getClass ()) return false ;
31
+ Position position = (Position ) o ;
32
+ return x == position .x && y == position .y ;
33
+ }
34
+
35
+ @ Override
36
+ public int hashCode () {
37
+ return Objects .hash (x , y );
38
+ }
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments