Insist on doing small things, then witness the magic
1234567891011
class Solution { public int largestPerimeter(int[] nums) { Arrays.sort(nums); for (int i = nums.length - 3; i >= 0; i--) { if (nums[i] + nums[i + 1] > nums[i + 2]) { return nums[i] + nums[i + 1] + nums[i + 2]; } } return 0; }}
sort然后两边之和大于第三边.
时间复杂度: O(nlogn)空间复杂度: O(logn)
Calm Patient Persistent