You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/3000-3099/3024.Type of Triangle II/README_EN.md
+79-4
Original file line number
Diff line number
Diff line change
@@ -46,24 +46,99 @@ As all the sides are of different lengths, it will form a scalene triangle.
46
46
47
47
## Solutions
48
48
49
-
### Solution 1
49
+
### Solution 1: Sorting + Case Discussion
50
+
51
+
First, we sort the array, and then we can classify and discuss according to the definition of a triangle.
52
+
53
+
- If the sum of the smallest two numbers is less than or equal to the largest number, then it cannot form a triangle, return "none".
54
+
- If the smallest number is equal to the largest number, then it is an equilateral triangle, return "equilateral".
55
+
- If the smallest number is equal to the middle number or the middle number is equal to the largest number, then it is an isosceles triangle, return "isosceles".
56
+
- Otherwise, return "scalene".
57
+
58
+
The time complexity is $O(1)$, and the space complexity is $O(1)$.
0 commit comments