返回介绍

solution / 1000-1099 / 1037.Valid Boomerang / README_EN

发布于 2024-06-17 01:03:31 字数 3064 浏览 0 评论 0 收藏 0

1037. Valid Boomerang

中文文档

Description

Given an array points where points[i] = [xi, yi] represents a point on the X-Y plane, return true _if these points are a boomerang_.

A boomerang is a set of three points that are all distinct and not in a straight line.

 

Example 1:

Input: points = [[1,1],[2,3],[3,2]]
Output: true

Example 2:

Input: points = [[1,1],[2,2],[3,3]]
Output: false

 

Constraints:

  • points.length == 3
  • points[i].length == 2
  • 0 <= xi, yi <= 100

Solutions

Solution 1

class Solution:
  def isBoomerang(self, points: List[List[int]]) -> bool:
    (x1, y1), (x2, y2), (x3, y3) = points
    return (y2 - y1) * (x3 - x2) != (y3 - y2) * (x2 - x1)
class Solution {
  public boolean isBoomerang(int[][] points) {
    int x1 = points[0][0], y1 = points[0][1];
    int x2 = points[1][0], y2 = points[1][1];
    int x3 = points[2][0], y3 = points[2][1];
    return (y2 - y1) * (x3 - x2) != (y3 - y2) * (x2 - x1);
  }
}
class Solution {
public:
  bool isBoomerang(vector<vector<int>>& points) {
    int x1 = points[0][0], y1 = points[0][1];
    int x2 = points[1][0], y2 = points[1][1];
    int x3 = points[2][0], y3 = points[2][1];
    return (y2 - y1) * (x3 - x2) != (y3 - y2) * (x2 - x1);
  }
};
func isBoomerang(points [][]int) bool {
  x1, y1 := points[0][0], points[0][1]
  x2, y2 := points[1][0], points[1][1]
  x3, y3 := points[2][0], points[2][1]
  return (y2-y1)*(x3-x2) != (y3-y2)*(x2-x1)
}
function isBoomerang(points: number[][]): boolean {
  const [x1, y1] = points[0];
  const [x2, y2] = points[1];
  const [x3, y3] = points[2];
  return (x1 - x2) * (y2 - y3) !== (x2 - x3) * (y1 - y2);
}
impl Solution {
  pub fn is_boomerang(points: Vec<Vec<i32>>) -> bool {
    let (x1, y1) = (points[0][0], points[0][1]);
    let (x2, y2) = (points[1][0], points[1][1]);
    let (x3, y3) = (points[2][0], points[2][1]);
    (x1 - x2) * (y2 - y3) != (x2 - x3) * (y1 - y2)
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文