Skip to content

Commit dd3cec6

Browse files
committed
Add solution and test-cases for problem 3024
1 parent a01e89c commit dd3cec6

File tree

3 files changed

+38
-23
lines changed

3 files changed

+38
-23
lines changed

leetcode/3001-3100/3024.Type-of-Triangle/README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
# [3024.Type of Triangle][title]
22

3-
> [!WARNING|style:flat]
4-
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5-
63
## Description
4+
You are given a **0-indexed** integer array `nums` of size `3` which can form the sides of a triangle.
5+
6+
- A triangle is called **equilateral** if it has all sides of equal length.
7+
- A triangle is called **isosceles** if it has exactly two sides of equal length.
8+
- A triangle is called **scalene** if all its sides are of different lengths.
9+
10+
Return a string representing the type of triangle that can be formed or `"none"` if it **cannot** form a triangle.
11+
712

813
**Example 1:**
914

1015
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
16+
Input: nums = [3,3,3]
17+
Output: "equilateral"
18+
Explanation: Since all the sides are of equal length, therefore, it will form an equilateral triangle.
1319
```
1420

15-
## 题意
16-
> ...
21+
**Example 2:**
1722

18-
## 题解
19-
20-
### 思路1
21-
> ...
22-
Type of Triangle
23-
```go
2423
```
25-
24+
Input: nums = [3,4,5]
25+
Output: "scalene"
26+
Explanation:
27+
nums[0] + nums[1] = 3 + 4 = 7, which is greater than nums[2] = 5.
28+
nums[0] + nums[2] = 3 + 5 = 8, which is greater than nums[1] = 4.
29+
nums[1] + nums[2] = 4 + 5 = 9, which is greater than nums[0] = 3.
30+
Since the sum of the two sides is greater than the third side for all three cases, therefore, it can form a triangle.
31+
As all the sides are of different lengths, it will form a scalene triangle.
32+
```
2633

2734
## 结语
2835

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(nums []int) string {
4+
if !(nums[0]+nums[1] > nums[2] && nums[0]+nums[2] > nums[1] && nums[1]+nums[2] > nums[0]) {
5+
return "none"
6+
}
7+
if nums[0] == nums[1] && nums[0] == nums[2] {
8+
return "equilateral"
9+
}
10+
if nums[0] == nums[1] || nums[0] == nums[2] || nums[1] == nums[2] {
11+
return "isosceles"
12+
}
13+
return "scalene"
514
}

leetcode/3001-3100/3024.Type-of-Triangle/Solution_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
14-
expect bool
13+
inputs []int
14+
expect string
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", []int{3, 3, 3}, "equilateral"},
17+
{"TestCase2", []int{3, 4, 5}, "scalene"},
1918
}
2019

2120
// 开始测试
@@ -30,10 +29,10 @@ func TestSolution(t *testing.T) {
3029
}
3130
}
3231

33-
// 压力测试
32+
// 压力测试
3433
func BenchmarkSolution(b *testing.B) {
3534
}
3635

37-
// 使用案列
36+
// 使用案列
3837
func ExampleSolution() {
3938
}

0 commit comments

Comments
 (0)