Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions leetcode/3001-3100/3024.Type-of-Triangle/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
# [3024.Type of Triangle][title]

> [!WARNING|style:flat]
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)

## Description
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.


**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
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:**

## 题解

### 思路1
> ...
Type of Triangle
```go
```

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.
```

## 结语

Expand Down
13 changes: 11 additions & 2 deletions leetcode/3001-3100/3024.Type-of-Triangle/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package Solution

func Solution(x bool) bool {
return x
func Solution(nums []int) string {
if !(nums[0]+nums[1] > nums[2] && nums[0]+nums[2] > nums[1] && nums[1]+nums[2] > nums[0]) {
return "none"
}
if nums[0] == nums[1] && nums[0] == nums[2] {
return "equilateral"
}
if nums[0] == nums[1] || nums[0] == nums[2] || nums[1] == nums[2] {
return "isosceles"
}
return "scalene"
}
13 changes: 6 additions & 7 deletions leetcode/3001-3100/3024.Type-of-Triangle/Solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
expect bool
inputs []int
expect string
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", []int{3, 3, 3}, "equilateral"},
{"TestCase2", []int{3, 4, 5}, "scalene"},
}

// 开始测试
Expand All @@ -30,10 +29,10 @@ func TestSolution(t *testing.T) {
}
}

// 压力测试
// 压力测试
func BenchmarkSolution(b *testing.B) {
}

// 使用案列
// 使用案列
func ExampleSolution() {
}
Loading