Skip to content

Commit fb885c5

Browse files
authored
Solved -> 610. Triangle Judgement
1 parent a822cdd commit fb885c5

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
3+
Problem Link -> https://leetcode.com/problems/triangle-judgement/description/?envType=study-plan-v2&envId=top-sql-50
4+
5+
------------------------------------------------------------- QUESTION -----------------------------------------------------------
6+
7+
Table: Triangle
8+
9+
+-------------+------+
10+
| Column Name | Type |
11+
+-------------+------+
12+
| x | int |
13+
| y | int |
14+
| z | int |
15+
+-------------+------+
16+
In SQL, (x, y, z) is the primary key column for this table.
17+
Each row of this table contains the lengths of three line segments.
18+
19+
20+
Report for every three line segments whether they can form a triangle.
21+
Return the result table in any order.
22+
The result format is in the following example.
23+
24+
25+
Example 1:
26+
27+
Input:
28+
Triangle table:
29+
+----+----+----+
30+
| x | y | z |
31+
+----+----+----+
32+
| 13 | 15 | 30 |
33+
| 10 | 20 | 15 |
34+
+----+----+----+
35+
36+
Output:
37+
+----+----+----+----------+
38+
| x | y | z | triangle |
39+
+----+----+----+----------+
40+
| 13 | 15 | 30 | No |
41+
| 10 | 20 | 15 | Yes |
42+
+----+----+----+----------+
43+
44+
*/
45+
46+
-- ----------------------------------------------------------- SOLUTION -----------------------------------------------------------
47+
48+
SELECT
49+
x, y, z,
50+
CASE
51+
WHEN (x + y) <= z THEN 'No'
52+
WHEN (y + z) <= x THEN 'No'
53+
WHEN (x + z) <= y THEN 'No'
54+
ELSE 'Yes'
55+
END AS triangle
56+
FROM Triangle;
57+
58+

0 commit comments

Comments
 (0)