Skip to content

Commit 31e308e

Browse files
authored
Create 0976 folder & Add cpp solution
1 parent 20e1216 commit 31e308e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int largestPerimeter(vector<int>& A) {
4+
priority_queue<int> q(A.begin(), A.end()) ; // 大顶堆
5+
6+
int a, b, c ;
7+
b = q.top() ;
8+
q.pop() ;
9+
c = q.top() ;
10+
q.pop() ;
11+
while ( !q.empty() )
12+
{
13+
a = b ;
14+
b = c ;
15+
c = q.top() ;
16+
q.pop() ;
17+
if ( b + c > a )
18+
return a + b + c ;
19+
}
20+
return 0 ;
21+
}
22+
};

0 commit comments

Comments
 (0)