본문 바로가기
코딩테스트/SQL

[LeetCode][MySQL] Triangle Judgement

by 포뇨j 2023. 12. 13.

https://leetcode.com/problems/triangle-judgement/

 

Triangle Judgement - LeetCode

Can you solve this real interview question? Triangle Judgement - Table: Triangle +-------------+------+ | Column Name | Type | +-------------+------+ | x | int | | y | int | | z | int | +-------------+------+ In SQL, (x, y, z) is the primary key column for

leetcode.com

 

select x, y, z,
(case when x+y>z and y+z>x and x+z>y then 'Yes'
else 'No' end) as triangle
from triangle

 

이 문제를 풀기 위해서는 삼각형의 성립 조건을 알아야했다.

구글링을 통해 찾아본 결과, 두 변의 길이의 합이 나머지 한 변의 길이보다 커야 한다.

case 조건문을 활용해 해당 조건을 적용해서 풀었다.