Skip to content

Latest commit

 

History

History
52 lines (46 loc) · 861 Bytes

1037.有效的回旋镖.md

File metadata and controls

52 lines (46 loc) · 861 Bytes

1037.有效的回旋镖

/*
 * @lc app=leetcode.cn id=1037 lang=typescript
 *
 * [1037] 有效的回旋镖
 */

// @lc code=start
function isBoomerang(points: number[][]): boolean {}
// @lc code=end

解法 1: 求斜率是否相等

function isBoomerang(points: number[][]): boolean {
  const [x1, y1] = [0, 1].map(i => points[0][i] - points[1][i]),
    [x2, y2] = [0, 1].map(i => points[1][i] - points[2][i])
  return x1 * y2 !== y1 * x2
}

Case

test.each([
  {
    input: {
      points: [
        [1, 1],
        [2, 3],
        [3, 2],
      ],
    },
    output: true,
  },
  {
    input: {
      points: [
        [1, 1],
        [2, 2],
        [3, 3],
      ],
    },
    output: false,
  },
])('input: points = $input.points', ({ input: { points }, output }) => {
  expect(isBoomerang(points)).toEqual(output)
})