Re: [閒聊] 每日LeetCode已回收
一開始想說慢慢加上去
找到比總和大的數就return
後來發先要先加完再減才是對的
2971. Find Polygon With the Largest Perimeter
class Solution {
public:
long long largestPerimeter(vector<int>& nums) {
long long sum=0;
int m=nums.size();
int count=m;
priority_queue<int> pq;
for(const int& n:nums){
sum+=n;
pq.push(n);
}
for(int i=0; i<m; i++){
if(pq.top()<sum-pq.top()) break;
sum-=pq.top();
pq.pop();
count--;
}
if(count<3) return -1;
return sum;
}
};
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.231.154.170 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1707964353.A.EF3.html
→
02/15 10:32,
1年前
, 1F
02/15 10:32, 1F
推
02/15 10:36,
1年前
, 2F
02/15 10:36, 2F
→
02/15 10:36,
1年前
, 3F
02/15 10:36, 3F
推
02/15 10:37,
1年前
, 4F
02/15 10:37, 4F
→
02/15 10:38,
1年前
, 5F
02/15 10:38, 5F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 677 之 719 篇):