Skip to content

Commit 509c991

Browse files
committed
Add solution #3024
1 parent 6674bc6 commit 509c991

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,880 LeetCode solutions in JavaScript
1+
# 1,881 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1855,6 +1855,7 @@
18551855
2962|[Count Subarrays Where Max Element Appears at Least K Times](./solutions/2962-count-subarrays-where-max-element-appears-at-least-k-times.js)|Medium|
18561856
2965|[Find Missing and Repeated Values](./solutions/2965-find-missing-and-repeated-values.js)|Easy|
18571857
2999|[Count the Number of Powerful Integers](./solutions/2999-count-the-number-of-powerful-integers.js)|Hard|
1858+
3024|[Type of Triangle](./solutions/3024-type-of-triangle.js)|Easy|
18581859
3042|[Count Prefix and Suffix Pairs I](./solutions/3042-count-prefix-and-suffix-pairs-i.js)|Easy|
18591860
3066|[Minimum Operations to Exceed Threshold Value II](./solutions/3066-minimum-operations-to-exceed-threshold-value-ii.js)|Medium|
18601861
3105|[Longest Strictly Increasing or Strictly Decreasing Subarray](./solutions/3105-longest-strictly-increasing-or-strictly-decreasing-subarray.js)|Easy|

solutions/3024-type-of-triangle.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* 3024. Type of Triangle
3+
* https://leetcode.com/problems/type-of-triangle/
4+
* Difficulty: Easy
5+
*
6+
* You are given a 0-indexed integer array nums of size 3 which can form the sides of a triangle.
7+
* - A triangle is called equilateral if it has all sides of equal length.
8+
* - A triangle is called isosceles if it has exactly two sides of equal length.
9+
* - A triangle is called scalene if all its sides are of different lengths.
10+
*
11+
* Return a string representing the type of triangle that can be formed or "none" if it cannot
12+
* form a triangle.
13+
*/
14+
15+
/**
16+
* @param {number[]} nums
17+
* @return {string}
18+
*/
19+
var triangleType = function(nums) {
20+
const [sideA, sideB, sideC] = nums.sort((a, b) => a - b);
21+
22+
if (sideA + sideB <= sideC) return 'none';
23+
if (sideA === sideB && sideB === sideC) return 'equilateral';
24+
if (sideA === sideB || sideB === sideC) return 'isosceles';
25+
26+
return 'scalene';
27+
};

0 commit comments

Comments
 (0)