119th LeetCode Weekly Contest Largest Perimeter Triangle
Given an array A
of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengths.
If it is impossible to form any triangle of non-zero area, return 0
.
Example 1:
Input: [2,1,2]
Output: 5
Example 2:
Input: [1,2,1]
Output: 0
Example 3:
Input: [3,2,3,4]
Output: 10
Example 4:
Input: [3,6,2,3]
Output: 8
Note:
3 <= A.length <= 10000
1 <= A[i] <= 10^6
又沒啥好說的,排序去一個個對就OK
相關推薦
119th LeetCode Weekly Contest Largest Perimeter Triangle
Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengths. If it
113th LeetCode Weekly Contest Largest Time for Given Digits
Given an array of 4 digits, return the largest 24 hour time that can be made. The smallest 24 hour time is 00:00, and the largest is 23:59. Starting
119th LeetCode Weekly Contest K Closest Points to Origin
We have a list of points on the plane. Find the K closest points to the origin (0, 0). (Here, the distance between two poin
119th LeetCode Weekly Contest Subarray Sums Divisible by K
Given an array A of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by K. Example 1:
「Leetcode」976. Largest Perimeter Triangle(C++)
mat break triangle size 大於 不能 clas angle largest 分析 好久不刷題真的思維僵化,要考慮到這樣一個結論:如果遞增的三個數\(x_i,x_{i+1},x_{i+2}\)不符合題意,那麽最大的兩邊之差一定大於等於第一條邊,那麽任何比
[Swift Weekly Contest 118]LeetCode976. 三角形的最大周長 | Largest Perimeter Triangle
Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengths. If it
Leetcode 976. Largest Perimeter Triangle
Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengt
109th LeetCode Weekly Contest Number of Recent Calls
Write a class RecentCounter to count recent requests. It has only one method: ping(int t), where t represents some time in milliseconds. R
LeetCode Weekly Contest 111 (C++)
Welcome to the 111th LeetCode Weekly Contest 941. Valid Mountain Array &
112th LeetCode Weekly Contest Minimum Increment to Make Array Unique
Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1. Return the least number of moves to make
112th LeetCode Weekly Contest Validate Stack Sequences
Given two sequences pushed and popped with distinct values, return true if and only if
LeetCode Weekly Contest 110 (C++)
Welcome to the 110th LeetCode Weekly Contest 937. Reorder Log Files - Easy 9
LeetCode Weekly Contest 112 (C++)
Welcome to the 112th LeetCode Weekly Contest 945. Minimum Increment to Make Array Unique &nb
114th LeetCode Weekly Contest Array of Doubled Pairs
Given an array of integers A with even length, return true if and only if it is possible to reorder it such that A[2 * i + 1] = 2
【leetcode Weekly Contest 107】927. Three Equal Parts
Given an array A of 0s and 1s, divide the array into 3 non-empty parts such that all of these parts represent the same binary value. If
LeetCode Weekly Contest 111 941&942&944
941 思路:找到最高點,最高點只能有一個,且不能是左右端點,從最高點往左右判斷,如果有不是單調遞減的就直接return false, class Solution { public: bool validMountainArray(vector<int&g
[LeetCode ] Weekly Contest 111
Valid Mountain Array Given an array A of integers, return true if and only if it is a valid mountain array. Recall that A is a mountai
116th LeetCode Weekly Contest Maximum Width Ramp
Given an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j]. The width
116th LeetCode Weekly Contest N-Repeated Element in Size 2N Array
In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeated N times. Return the element
115th LeetCode Weekly Contest Prison Cells After N Days
There are 8 prison cells in a row, and each cell is either occupied or vacant. Each day, whether the cell is occupied or vacant changes according to the f