Re: [閒聊] LeetCode Weekly Contest 413

看板Marginalman作者 (死肥肥社管)時間1年前 (2024/09/01 13:06), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/7 (看更多)
虛擬參賽一波 q1 判斷奇偶 class Solution { public: bool checkTwoChessboards(string coordinate1, string coordinate2) { int c1 = coordinate1[0]-'a' + coordinate1[1] - '1'; int c2 = coordinate2[0]-'a' + coordinate2[1] - '1'; return c1 % 2 == c2 % 2; } }; q2 size k的heap class Solution { public: vector<int> resultsArray(vector<vector<int>>& queries, int k) { priority_queue<int> pq; vector<int> ans; for(auto& q : queries){ int dist = abs(q[0])+abs(q[1]); pq.push(dist); if(pq.size() > k){ pq.pop(); } if(pq.size() < k){ ans.push_back(-1); } else { ans.push_back(pq.top()); } } return ans; } }; q3不會 q4不會 我好爛 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.228.87.250 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1725167202.A.CA3.html
文章代碼(AID): #1cq_PYoZ (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cq_PYoZ (Marginalman)