题解 | #小红的最小三角形周长#
小红的最小三角形周长
https://www.nowcoder.com/practice/959c3b1ff4794ecea41a2569892ab4d4
class Solution: def hongstriangle(self , nums: List[int]) -> int: # write code here n = len(nums) nums=sorted(nums) for j in range(1,n-1): c = nums[j+1] - nums[j] for i in range(j): if nums[i] > c: rs = nums[i]+nums[j]+nums[j+1] return rs
这道题最巧妙的地方在于最大的两边必定在数组中相邻!!