Skip to content

Commit 9791cad

Browse files
add 1037
1 parent df459ab commit 9791cad

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Your ideas/fixes/algorithms are more than welcome!
2727

2828
| # | Title | Solutions | Time | Space | Video | Difficulty | Tag
2929
|-----|----------------|---------------|---------------|---------------|--------|-------------|-------------
30+
|1037|[Valid Boomerang](https://leetcode.com/problems/valid-boomerang/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1037.java) | O(1) | O(1) | |Easy|Math|
3031
|1033|[Moving Stones Until Consecutive](https://leetcode.com/problems/moving-stones-until-consecutive/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1033.java) | O(1) | O(1) | |Easy|Math|
3132
|1030|[Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1030.java) | O(R*C) | O(1) | |Easy|
3233
|1022|[Sum of Root To Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1022.java) | O(n) | O(n) | |Easy|
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fishercoder.solutions;
2+
3+
/**
4+
* 1037. Valid Boomerang
5+
*
6+
* A boomerang is a set of 3 points that are all distinct and not in a straight line.
7+
*
8+
* Given a list of three points in the plane, return whether these points are a boomerang.
9+
*
10+
* Example 1:
11+
* Input: [[1,1],[2,3],[3,2]]
12+
* Output: true
13+
*
14+
* Example 2:
15+
* Input: [[1,1],[2,2],[3,3]]
16+
* Output: false
17+
*
18+
* Note:
19+
* points.length == 3
20+
* points[i].length == 2
21+
* 0 <= points[i][j] <= 100
22+
* */
23+
public class _1037 {
24+
public static class Solution1 {
25+
public boolean isBoomerang(int[][] points) {
26+
return (points[1][1] - points[0][1]) * (points[2][0] - points[0][0]) != (points[2][1] - points[0][1]) * (points[1][0] - points[0][0]);
27+
}
28+
}
29+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1037;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static junit.framework.Assert.assertEquals;
8+
9+
public class _1037Test {
10+
private static _1037.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1037.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(true, solution1.isBoomerang(new int[][]{new int[]{1, 1}, new int[]{2, 3}, new int[]{3, 2}}));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(false, solution1.isBoomerang(new int[][]{new int[]{1, 1}, new int[]{2, 2}, new int[]{3, 3}}));
25+
}
26+
27+
@Test
28+
public void test3() {
29+
assertEquals(true, solution1.isBoomerang(new int[][]{new int[]{0, 0}, new int[]{0, 2}, new int[]{2, 1}}));
30+
}
31+
32+
@Test
33+
public void test4() {
34+
assertEquals(false, solution1.isBoomerang(new int[][]{new int[]{0, 0}, new int[]{1, 1}, new int[]{1, 1}}));
35+
}
36+
37+
}

0 commit comments

Comments
 (0)