2024-08-07 18:58
Day 48 每日一題 Leetcode
-
**✍️ 611. Valid Triangle Number**
給一個 int arry, 任取三數可以構成三角形
例如
```
nums = [2,2,3,4]
Output: 3
Explanation: Valid combinations are:
2,3,4 (using the first 2)
2,3,4 (using the second 2)
2,2,3
```
**🧠 思考過程**
先用 Sort 將 arr 排序,找到符合下列條件的三個數字
a+b ≥ c
C 一定是最大值,倒序的從右往左邊遍歷,A初始 index = 0,B初始 index = C-1,這樣可以得知當條件符合時,A-B之間的組合都符合條件
T:O(n^2)
S:O(1)