-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy path3024-type-of-triangle.js
More file actions
27 lines (24 loc) · 904 Bytes
/
3024-type-of-triangle.js
File metadata and controls
27 lines (24 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* 3024. Type of Triangle
* https://leetcode.com/problems/type-of-triangle/
* Difficulty: Easy
*
* You are given a 0-indexed integer array nums of size 3 which can form the sides of a triangle.
* - A triangle is called equilateral if it has all sides of equal length.
* - A triangle is called isosceles if it has exactly two sides of equal length.
* - A triangle is called scalene if all its sides are of different lengths.
*
* Return a string representing the type of triangle that can be formed or "none" if it cannot
* form a triangle.
*/
/**
* @param {number[]} nums
* @return {string}
*/
var triangleType = function(nums) {
const [sideA, sideB, sideC] = nums.sort((a, b) => a - b);
if (sideA + sideB <= sideC) return 'none';
if (sideA === sideB && sideB === sideC) return 'equilateral';
if (sideA === sideB || sideB === sideC) return 'isosceles';
return 'scalene';
};