Skip to content

Commit 7d1d401

Browse files
committed
Sync LeetCode submission Runtime - 0 ms (100.00%), Memory - 17.9 MB (10.54%)
1 parent db5ed0b commit 7d1d401

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

3321-type-of-triangle/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of size <code>3</code> which can form the sides of a triangle.</p>
2+
3+
<ul>
4+
<li>A triangle is called <strong>equilateral</strong> if it has all sides of equal length.</li>
5+
<li>A triangle is called <strong>isosceles</strong> if it has exactly two sides of equal length.</li>
6+
<li>A triangle is called <strong>scalene</strong> if all its sides are of different lengths.</li>
7+
</ul>
8+
9+
<p>Return <em>a string representing</em> <em>the type of triangle that can be formed </em><em>or </em><code>&quot;none&quot;</code><em> if it <strong>cannot</strong> form a triangle.</em></p>
10+
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
13+
14+
<pre>
15+
<strong>Input:</strong> nums = [3,3,3]
16+
<strong>Output:</strong> &quot;equilateral&quot;
17+
<strong>Explanation:</strong> Since all the sides are of equal length, therefore, it will form an equilateral triangle.
18+
</pre>
19+
20+
<p><strong class="example">Example 2:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> nums = [3,4,5]
24+
<strong>Output:</strong> &quot;scalene&quot;
25+
<strong>Explanation:</strong>
26+
nums[0] + nums[1] = 3 + 4 = 7, which is greater than nums[2] = 5.
27+
nums[0] + nums[2] = 3 + 5 = 8, which is greater than nums[1] = 4.
28+
nums[1] + nums[2] = 4 + 5 = 9, which is greater than nums[0] = 3.
29+
Since the sum of the two sides is greater than the third side for all three cases, therefore, it can form a triangle.
30+
As all the sides are of different lengths, it will form a scalene triangle.
31+
</pre>
32+
33+
<p>&nbsp;</p>
34+
<p><strong>Constraints:</strong></p>
35+
36+
<ul>
37+
<li><code>nums.length == 3</code></li>
38+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
39+
</ul>

3321-type-of-triangle/solution.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Approach: Math
2+
3+
class Solution:
4+
def triangleType(self, nums: List[int]) -> str:
5+
nums.sort()
6+
if nums[0] + nums[1] <= nums[2]:
7+
return "none"
8+
elif nums[0] == nums[2]:
9+
return "equilateral"
10+
elif nums[0] == nums[1] or nums[1] == nums[2]:
11+
return "isosceles"
12+
else:
13+
return "scalene"
14+

0 commit comments

Comments
 (0)