[LeetCode] Valid Boomerang

아르당·2026년 3월 27일

LeetCode

목록 보기
225/263
post-thumbnail

문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음

Problem

X-Y 평면상의 점을 나타내는 points[i] = [xi, yi]로 표현되는 배열 points가 주어졌을 때, 이 점들이 부메랑이면 true를 반환해라.
부메랑은 서로 다른 세점으로 이루어져 있고, 이 점들은 모두 일직선상에 있지 않다.

Example

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

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

Constraints

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

Solved

class Solution {
    public boolean isBoomerang(int[][] points) {
        return (points[1][1] - points[0][1]) * (points[2][0] - points[1][0]) !=
            (points[2][1] - points[1][1]) * (points[1][0] - points[0][0]);
    }
}
profile
내 마음대로 코드 작성하는 세상

0개의 댓글