作者wu10200512 (廷廷)
看板Marginalman
標題Re: [閒聊] 每日LeetCode
時間Thu Feb 15 10:32:31 2024
一開始想說慢慢加上去
找到比總和大的數就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
→ DJYOSHITAKA: 大師 02/15 10:32
推 PyTorch: 廷廷 你看乒乓the animation了嘛 02/15 10:36
→ wu10200512: 等我回新竹 02/15 10:36
推 sustainer123: 大師 02/15 10:37
→ JIWP: 大師 02/15 10:38