LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
<풀이>
-- 1.출력: x,y,z, 삼각형 만들 수 있는지 여부
-- 2.필터: X
-- 3.정렬: X
SELECT *
,CASE WHEN x + y > z AND x + z > y AND y + z > x THEN 'Yes' ELSE 'No' END AS 'triangle'
FROM triangle
비슷한 문제를 해커랭크에서도 풀었던 것 같다.
삼각형의 길이 조건을 기억하면 간단히 풀 수 있는 문제
'가장 긴 변은 나머지 두 변의 합보다 짧다'
즉, '어떤 두 변의 길이의 합도 나머지 한 변보다 크다'를 만족하면 된다.
* CASE WHEN ~ END : 마지막 END를 잊지 말자!
'SQL > LeetCode' 카테고리의 다른 글
| [SQL] LeetCode: 1164. Product Price at a Given Date (0) | 2024.03.09 |
|---|---|
| [SQL] LeetCode: 180. Consecutive Numbers (0) | 2024.02.08 |
| [SQL] LeetCode : 184. Department Highest Salary (0) | 2024.01.31 |
| [SQL] LeetCode: 1789. Primary Department for Each Employee (1) | 2024.01.26 |
| [SQL] LeetCode: 1731. The Number of Employees Which Report to Each Employee (0) | 2024.01.17 |