Skip to content

Commit b136d5a

Browse files
authored
update: 添加问题“3024.三角形类型”的代码和题解(#943)
* 3024: WA.cpp (#942) 三角形两边之和必须大于第三边。。。 不是大于等于 Signed-off-by: LetMeFly666 <[email protected]> * 3024: AC.cpp+Py | Test.java (#942) Signed-off-by: LetMeFly666 <[email protected]> * update: 添加问题“3024.三角形类型”的代码和题解(#943) Signed-off-by: LetMeFly666 <[email protected]> --------- Signed-off-by: LetMeFly666 <[email protected]>
1 parent 1f6d9e2 commit b136d5a

12 files changed

+378
-2
lines changed

Codes/3024-type-of-triangle.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-19 13:22:46
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-19 13:28:44
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
string triangleType(vector<int>& nums) {
14+
sort(nums.begin(), nums.end());
15+
if (nums[0] + nums[1] <= nums[2]) {
16+
return "none";
17+
}
18+
if (nums[0] == nums[1] && nums[1] == nums[2]) {
19+
return "equilateral";
20+
}
21+
if (nums[0] == nums[1] || nums[1] == nums[2]) {
22+
return "isosceles";
23+
}
24+
return "scalene";
25+
}
26+
};

Codes/3024-type-of-triangle.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-19 13:22:46
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-19 13:35:48
6+
*/
7+
package main
8+
9+
import "sort"
10+
11+
func triangleType(nums []int) string {
12+
sort.Ints(nums)
13+
if nums[0] + nums[1] <= nums[2] {
14+
return "none"
15+
}
16+
if nums[0] == nums[1] && nums[1] == nums[2] {
17+
return "equilateral"
18+
}
19+
if nums[0] == nums[1] || nums[1] == nums[2] {
20+
return "isosceles"
21+
}
22+
return "scalene"
23+
}

Codes/3024-type-of-triangle.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-19 13:22:46
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-19 13:32:46
6+
*/
7+
import java.util.Arrays;
8+
9+
class Solution {
10+
public String triangleType(int[] nums) {
11+
Arrays.sort(nums);
12+
if (nums[0] + nums[1] <= nums[2]) {
13+
return "none";
14+
}
15+
if (nums[0] == nums[1] && nums[1] == nums[2]) {
16+
return "equilateral";
17+
}
18+
if (nums[0] == nums[1] || nums[1] == nums[2]) {
19+
return "isosceles";
20+
}
21+
return "scalene";
22+
}
23+
}

Codes/3024-type-of-triangle.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-05-19 13:22:46
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-05-19 13:30:25
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def triangleType(self, nums: List[int]) -> str:
11+
nums.sort()
12+
a, b, c = nums
13+
if a + b <= c:
14+
return "none"
15+
if a == b == c:
16+
return "equilateral"
17+
if a == b or b == c:
18+
return "isosceles"
19+
return "scalene"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@
890890
|2999.统计强大整数的数目|困难|<a href="https://leetcode.cn/problems/count-the-number-of-powerful-integers/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/04/12/LeetCode%202999.%E7%BB%9F%E8%AE%A1%E5%BC%BA%E5%A4%A7%E6%95%B4%E6%95%B0%E7%9A%84%E6%95%B0%E7%9B%AE/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/147191672" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-the-number-of-powerful-integers/solutions/3649695/letmefly-2999tong-ji-qiang-da-zheng-shu-jnya8/" target="_blank">LeetCode题解</a>|
891891
|3011.判断一个数组是否可以变为有序|中等|<a href="https://leetcode.cn/problems/find-if-array-can-be-sorted/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/07/13/LeetCode%203011.%E5%88%A4%E6%96%AD%E4%B8%80%E4%B8%AA%E6%95%B0%E7%BB%84%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%8F%98%E4%B8%BA%E6%9C%89%E5%BA%8F/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/140391465" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-if-array-can-be-sorted/solutions/2841665/letmefly-3011pan-duan-yi-ge-shu-zu-shi-f-i9ck/" target="_blank">LeetCode题解</a>|
892892
|3019.按键变更的次数|简单|<a href="https://leetcode.cn/problems/number-of-changing-keys/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/01/07/LeetCode%203019.%E6%8C%89%E9%94%AE%E5%8F%98%E6%9B%B4%E7%9A%84%E6%AC%A1%E6%95%B0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/144983704" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/number-of-changing-keys/solutions/3040949/letmefly-3019an-jian-bian-geng-de-ci-shu-pgzx/" target="_blank">LeetCode题解</a>|
893+
|3024.三角形类型|简单|<a href="https://leetcode.cn/problems/type-of-triangle/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/05/19/LeetCode%203024.%E4%B8%89%E8%A7%92%E5%BD%A2%E7%B1%BB%E5%9E%8B/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/148061722" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/type-of-triangle/solutions/3680826/letmefly-3024san-jiao-xing-lei-xing-shou-q46h/" target="_blank">LeetCode题解</a>|
893894
|3033.修改矩阵|简单|<a href="https://leetcode.cn/problems/modify-the-matrix/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/07/05/LeetCode%203033.%E4%BF%AE%E6%94%B9%E7%9F%A9%E9%98%B5/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/140219034" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/modify-the-matrix/solutions/2832430/letmefly-3033xiu-gai-ju-zhen-yuan-di-xiu-e0cy/" target="_blank">LeetCode题解</a>|
894895
|3038.相同分数的最大操作数目I|简单|<a href="https://leetcode.cn/problems/maximum-number-of-operations-with-the-same-score-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/06/07/LeetCode%203038.%E7%9B%B8%E5%90%8C%E5%88%86%E6%95%B0%E7%9A%84%E6%9C%80%E5%A4%A7%E6%93%8D%E4%BD%9C%E6%95%B0%E7%9B%AEI/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/139535702" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/maximum-number-of-operations-with-the-same-score-i/solutions/2804245/letmefly-3038xiang-tong-fen-shu-de-zui-d-dkj7/" target="_blank">LeetCode题解</a>|
895896
|3046.分割数组|简单|<a href="https://leetcode.cn/problems/split-the-array/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/12/28/LeetCode%203046.%E5%88%86%E5%89%B2%E6%95%B0%E7%BB%84/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/144789679" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/split-the-array/solutions/3032725/letmefly-3046fen-ge-shu-zu-ji-shu-by-tis-33vv/" target="_blank">LeetCode题解</a>|
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
---
2+
title: 3024.三角形类:手速题
3+
date: 2025-05-19 13:36:41
4+
tags: [题解, LeetCode, 简单, 数组, 数学, 排序]
5+
categories: [题解, LeetCode]
6+
---
7+
8+
# 【LetMeFly】3024.三角形类型:手速题
9+
10+
力扣题目链接:[https://leetcode.cn/problems/type-of-triangle/](https://leetcode.cn/problems/type-of-triangle/)
11+
12+
<p>给你一个下标从 <strong>0</strong>&nbsp;开始长度为 <code>3</code>&nbsp;的整数数组&nbsp;<code>nums</code>&nbsp;,需要用它们来构造三角形。</p>
13+
14+
<ul>
15+
<li>如果一个三角形的所有边长度相等,那么这个三角形称为&nbsp;<strong>equilateral</strong>&nbsp;。</li>
16+
<li>如果一个三角形恰好有两条边长度相等,那么这个三角形称为&nbsp;<strong>isosceles</strong>&nbsp;。</li>
17+
<li>如果一个三角形三条边的长度互不相同,那么这个三角形称为&nbsp;<strong>scalene</strong>&nbsp;。</li>
18+
</ul>
19+
20+
<p>如果这个数组无法构成一个三角形,请你返回字符串&nbsp;<code>"none"</code>&nbsp;,否则返回一个字符串表示这个三角形的类型。</p>
21+
22+
<p>&nbsp;</p>
23+
24+
<p><strong class="example">示例 1:</strong></p>
25+
26+
<pre>
27+
<b>输入:</b>nums = [3,3,3]
28+
<b>输出:</b>"equilateral"
29+
<b>解释:</b>由于三条边长度相等,所以可以构成一个等边三角形,返回 "equilateral" 。
30+
</pre>
31+
32+
<p><strong class="example">示例 2:</strong></p>
33+
34+
<pre>
35+
<b>输入:</b>nums = [3,4,5]
36+
<b>输出:</b>"scalene"
37+
<b>解释:</b>
38+
nums[0] + nums[1] = 3 + 4 = 7 ,大于 nums[2] = 5 <span style="text-wrap: wrap;">。</span>
39+
nums[0] + nums[2] = 3 + 5 = 8 ,大于 nums[1] = 4 。
40+
nums[1] + nums[2] = 4 + 5 = 9 ,大于 nums[0] = 3 。
41+
由于任意两边之和都大于第三边,所以可以构成一个三角形,因为三条边的长度互不相等,所以返回 "scalene"。
42+
</pre>
43+
44+
<p><strong>提示:</strong></p>
45+
46+
<ul>
47+
<li><code>nums.length == 3</code></li>
48+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
49+
</ul>
50+
51+
52+
53+
## 解题方法:if-else
54+
55+
为了判断给定三个变长是否满足三角形的基本性质(以及是否有两边等长),可以先将三个数从小到大排个序。
56+
57+
+ 如果两边之和小于等于第三边则不能构成三角形
58+
+ 如果三边全相等则为正三角形
59+
+ 如果有任何两边相等则为等腰三角形
60+
+ 否则为普通三角形
61+
62+
以上。
63+
64+
+ 时间复杂度$O(1)$
65+
+ 空间复杂度$O(1)$
66+
67+
### AC代码
68+
69+
#### C++
70+
71+
```cpp
72+
/*
73+
* @Author: LetMeFly
74+
* @Date: 2025-05-19 13:22:46
75+
* @LastEditors: LetMeFly.xyz
76+
* @LastEditTime: 2025-05-19 13:28:44
77+
*/
78+
class Solution {
79+
public:
80+
string triangleType(vector<int>& nums) {
81+
sort(nums.begin(), nums.end());
82+
if (nums[0] + nums[1] <= nums[2]) {
83+
return "none";
84+
}
85+
if (nums[0] == nums[1] && nums[1] == nums[2]) {
86+
return "equilateral";
87+
}
88+
if (nums[0] == nums[1] || nums[1] == nums[2]) {
89+
return "isosceles";
90+
}
91+
return "scalene";
92+
}
93+
};
94+
```
95+
96+
#### Python
97+
98+
```python
99+
'''
100+
Author: LetMeFly
101+
Date: 2025-05-19 13:22:46
102+
LastEditors: LetMeFly.xyz
103+
LastEditTime: 2025-05-19 13:30:25
104+
'''
105+
from typing import List
106+
107+
class Solution:
108+
def triangleType(self, nums: List[int]) -> str:
109+
nums.sort()
110+
a, b, c = nums
111+
if a + b <= c:
112+
return "none"
113+
if a == b == c:
114+
return "equilateral"
115+
if a == b or b == c:
116+
return "isosceles"
117+
return "scalene"
118+
```
119+
120+
#### Java
121+
122+
```java
123+
/*
124+
* @Author: LetMeFly
125+
* @Date: 2025-05-19 13:22:46
126+
* @LastEditors: LetMeFly.xyz
127+
* @LastEditTime: 2025-05-19 13:32:46
128+
*/
129+
import java.util.Arrays;
130+
131+
class Solution {
132+
public String triangleType(int[] nums) {
133+
Arrays.sort(nums);
134+
if (nums[0] + nums[1] <= nums[2]) {
135+
return "none";
136+
}
137+
if (nums[0] == nums[1] && nums[1] == nums[2]) {
138+
return "equilateral";
139+
}
140+
if (nums[0] == nums[1] || nums[1] == nums[2]) {
141+
return "isosceles";
142+
}
143+
return "scalene";
144+
}
145+
}
146+
```
147+
148+
#### Go
149+
150+
```go
151+
/*
152+
* @Author: LetMeFly
153+
* @Date: 2025-05-19 13:22:46
154+
* @LastEditors: LetMeFly.xyz
155+
* @LastEditTime: 2025-05-19 13:35:48
156+
*/
157+
package main
158+
159+
import "sort"
160+
161+
func triangleType(nums []int) string {
162+
sort.Ints(nums)
163+
if nums[0] + nums[1] <= nums[2] {
164+
return "none"
165+
}
166+
if nums[0] == nums[1] && nums[1] == nums[2] {
167+
return "equilateral"
168+
}
169+
if nums[0] == nums[1] || nums[1] == nums[2] {
170+
return "isosceles"
171+
}
172+
return "scalene"
173+
}
174+
```
175+
176+
> 同步发文于[CSDN](https://letmefly.blog.csdn.net/article/details/148061722)和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2025/05/19/LeetCode%203024.%E4%B8%89%E8%A7%92%E5%BD%A2%E7%B1%BB%E5%9E%8B/)哦~
177+
>
178+
> 千篇源码题解[已开源](https://github.com/LetMeFly666/LeetCode)

Solutions/Other-English-LearningNotes-SomeWords.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,17 @@ categories: [自用]
11571157
|masculine|adj. 男人的,像男人的,阳性的<br/>n. 阳性|
11581158
|liability|n. 责任,义务,不利因素,欠债,负债,可能性|
11591159
|tactics|n. 战术,策略|
1160+
|||
1161+
|circumference|n. 圆周,圆周长|
1162+
|apprize|v. 通知,报告<details><summary>例句</summary>He asked a real estate agent to <font color="#28bea0">apprize</font> the house.<br/>他请一名房产中介来评估房子。</details>|
1163+
|intimation|n. 暗示,透漏,间接表示|
1164+
|||
1165+
|pope|n. 教皇|
1166+
|||
1167+
|amends|n. 赔偿,赎罪,复原|
1168+
|twilight|n. 暮色,黄昏,没落时期,衰退期<br/>adj. 奇妙神秘的,虚幻的,朦胧的,界限不清的|
1169+
|||
1170+
|ascertain|v. 查明,弄清|
11601171

11611172
<p class="wordCounts">单词收录总数</p>
11621173

Solutions/Other-Japanese-LearningNotes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ xx型
278278
|塩(しお)||
279279
|醬油(しょうゆ)|酱油|
280280
|砂糖(さとう)||
281+
|綿飴(わたあめ)|棉花糖|
281282
|ミント|薄荷|
282283
|コーヒー|咖啡|
283284
|カレー|咖喱|
@@ -413,6 +414,7 @@ xx型
413414
|茶碗(ちゃわん)||
414415
|お金(おかね)||
415416
|財布(さいふ)|钱包|
417+
|パスワード|密码|
416418
|時計(とけい)|时钟|
417419
|腕時計(うでどけい)|手表|
418420
|ベッド||
@@ -475,6 +477,7 @@ xx型
475477
|切手(きって)|邮票|
476478
|あめ||
477479
|せっけん|香皂|
480+
|ハンドジェル|洗手液|
478481
|ダイヤモンド|钻石|
479482
|エレベーター|电梯|
480483
|階段(かいだん)|楼梯|
@@ -693,6 +696,7 @@ xx型
693696
|とり||
694697
|猫(ねこ)||
695698
|犬(いぬ)||
699+
|兎(うさぎ)|兔子|
696700
|ペット|宠物|
697701
|サル|猴子|
698702
|キリン|长颈鹿|
@@ -786,6 +790,7 @@ xx型
786790
|だれ||
787791
|彼女(かのじょ)|她/女朋友|
788792
|彼氏(かれし)|男朋友|
793+
|ルームメイト|室友|
789794
|女(おんな)|女的|
790795
|女の子(こ)|女孩|
791796
|男(おとこ)|男的|

tryGoPy/MGJW/nextweek/chat.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!--
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-18 16:58:47
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-18 16:58:49
6+
-->
7+
通过文字隐蔽传输信息的方式

tryGoPy/MGJW/nextweek/todo.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!--
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-18 16:33:56
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-18 16:58:37
6+
-->
7+
先找找有没有通过文字隐蔽传输的方式
8+
9+
针对性只能要求应用
10+
建议泛化方法
11+
12+
可以支持图片xx进行泛化,但至少必须支持文字
13+
14+
15+
例如使用两张“一摸一样”的表情包diff进行编码

0 commit comments

Comments
 (0)