Re: [閒聊] 每日LeetCode已回收

看板Marginalman作者 (廷廷)時間1年前 (2024/02/15 10:32), 編輯推噓2(203)
留言5則, 5人參與, 1年前最新討論串677/719 (看更多)
一開始想說慢慢加上去 找到比總和大的數就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
廷廷 你看乒乓the animation了嘛
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
文章代碼(AID): #1bpNV1xp (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1bpNV1xp (Marginalman)