본문 바로가기

Algorithm/Implementation

(SQL) - LeetCode (easy) 610. Triangle Judgement

반응형

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

 

Triangle Judgement - LeetCode

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

leetcode.com

case문을 사용해본 문제였습니다.

📕 풀이방법

📔 풀이과정

삼각형의 조건은 한 변 < 나머지 두 변의 합입니다. 따라서 그렇지 못하다면 No를 아니라면 Yes를 case문으로 정의해 해당 column명을 trangle로 select하면 됩니다.


📕 Code

📔 MySQL & Oracle

select x, y, z, 
case when
    x >= y + z or y >= x + z or z >= x + y then 'No'
else
    'Yes'
end as triangle 
from triangle

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.