Re: [閒聊] 每日leetcode

看板Marginalman作者 (6B)時間3月前 (2025/09/03 01:08), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1513/1548 (看更多)
3025. 圖畫出來就清楚ㄌ sort過之後畫boundary 奇怪為啥我分兩次sort會歪掉:3 好吧好吧 class Solution { public: int numberOfPairs(vector<vector<int>>& p) { // wa to sd // p[y][x] sort by x int n = p.size(); //sort(p.begin(), p.end(), [](auto& a, auto& b){return a[0] > b[0];}); sort(p.begin(), p.end(), [](auto& a, auto& b){ if(a[1] < b[1]) return true; else if(a[1] == b[1] and a[0] > b[0]) return true; return false; }); int res = 0; for(int i = 0; i < n; i++){ int y = p[i][0], x = p[i][1]; //cout << y << " " << x << '\n'; int bottom = -1; for(int j = i+1; j < n and bottom < y; j++){ int cy = p[j][0], cx = p[j][1]; if(cy > y) continue; if(bottom < cy){ res++; bottom = cy; } } } return res; } }; ----- Sent from JPTT on my iPad -- 很姆的咪 姆之咪 http://i.imgur.com/5sw7QOj.jpg
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.135.99.218 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1756832927.A.3AB.html
文章代碼(AID): #1ejoIVEh (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1ejoIVEh (Marginalman)