Re: [闲聊] 每日LeetCode

楼主: wu10200512 (廷廷)   2024-02-15 10:32:31
一开始想说慢慢加上去
找到比总和大的数就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
作者: DJYOSHITAKA (Evans)   2023-02-15 10:32:00
大师
作者: PyTorch (屁眼火炬)   2024-02-15 10:36:00
廷廷 你看乒乓the animation了嘛
楼主: wu10200512 (廷廷)   2024-02-15 10:36:00
等我回新竹
作者: sustainer123 (caster)   2024-02-15 10:37:00
大师
作者: JIWP (JIWP)   2024-02-15 10:38:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com