#3024
Type of Triangle
pupil · 480 · lc easy +27 · verified · 44.1% accepted · 458 likes · top 26%
Description
You are given a 0-indexed integer array nums of size 3 whose elements can form triangle sides.
- A triangle with all sides equal is equilateral.
- A triangle with exactly two equal sides is isosceles.
- A triangle with all sides different is scalene.
Return a string describing the type of triangle, or "none" if the three values cannot form a triangle.
Example 1:
Input: nums = [3,3,3]
Output: "equilateral"
Explanation: Since all the sides are of equal length, therefore, it will form an equilateral triangle.
Example 2:
Input: nums = [3,4,5]
Output: "scalene"
Explanation:
nums[0] + nums[1] = 3 + 4 = 7, which is greater than nums[2] = 5.
nums[0] + nums[2] = 3 + 5 = 8, which is greater than nums[1] = 4.
nums[1] + nums[2] = 4 + 5 = 9, which is greater than nums[0] = 3.
Since the sum of the two sides is greater than the third side for all three cases, therefore, it can form a triangle.
As all the sides are of different lengths, it will form a scalene triangle.
Code
1
2
3