tianyun há 3 anos atrás
pai
commit
f8d49259ca
1 ficheiros alterados com 27 adições e 0 exclusões
  1. 27 0
      leetcode/src/main/java/Solution1037.java

+ 27 - 0
leetcode/src/main/java/Solution1037.java

@@ -0,0 +1,27 @@
+/**
+ * solution1037
+ * 1037. 有效的回旋镖
+ * 给定一个数组 points ,其中 points[i] = [xi, yi] 表示 X-Y 平面上的一个点,如果这些点构成一个 回旋镖 则返回 true 。
+ * <p>
+ * 回旋镖 定义为一组三个点,这些点 各不相同 且 不在一条直线上 。
+ *
+ * @author mlamp
+ * @date 2022/06/08
+ */
+public class Solution1037 {
+    public boolean isBoomerang(int[][] points) {
+        int m = points.length, n = points[0].length;
+        if (m != 3) {
+            return false;
+        }
+        if ((points[0][0] - points[1][0]) * (points[1][1] - points[2][1]) == (points[0][1] - points[1][1]) * (points[1][0] - points[2][0])) {
+            return false;
+        }
+        return true;
+    }
+
+    public static void main(String[] args) {
+        System.out.println(new Solution1037().isBoomerang(new int[][]{{1, 1}, {2, 3}, {3, 2}}));
+        System.out.println(new Solution1037().isBoomerang(new int[][]{{1, 1}, {2, 2}, {3, 3}}));
+    }
+}