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

看板Marginalman作者 (是oin捏)時間1年前 (2024/04/08 11:32), 編輯推噓-4(043)
留言7則, 4人參與, 1年前最新討論串104/1548 (看更多)
※ 引述 《sustainer123 (caster)》 之銘言: :   : https://leetcode.com/problems/number-of-students-unable-to-eat-lunch :   : 1700. Number of Students Unable to Eat Lunch :   : 齁樓提供PM跟MC兩種貼貼 分別用0跟1表示 :   : 全部齁粉站在一queue 每個齁粉喜歡PM或MC :   : 貼貼數量與齁粉數量相等 貼貼被放在一stack :   : 如果queue前面的齁粉喜歡stack頂端的貼貼 他會拿走貼貼 : 否則他會放下貼貼並回到queue最後面 :   : 循環反覆 直至剩下的齁粉都不想拿stack最頂端的貼貼 他們就會去公園 :   : 請回傳公園民的數量 :   解法思路 : 照著題目要求的做 欸欸我leetcode point 2400了欸 這個要換什麼比較好 有人有換過東西嗎 好像可以炫耀欸 class Solution { public: int countStudents(vector<int>& students, vector<int>& sandwiches) { int wp = 0; int sp = 0; int one = 0; int zero = 0; int len = students.size(); int lens = sandwiches.size(); for(int k : students) { if(k)one ++; else zero ++; } int ok = 1; int hungry = len ; while(wp < lens) { if(sandwiches[wp] == 1) { if(one == 0)return hungry; while(students[sp%len] != 1) { sp ++; } students.erase( students.begin()+sp%len ); len --; hungry --; one --; wp ++; } else if(sandwiches[wp] == 0) { if(zero == 0)return hungry; while(students[sp%len] != 0) { sp ++; } students.erase( students.begin()+sp%len ); len --; hungry --; zero --; wp ++; } } return hungry; } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.162.47.49 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1712547143.A.F84.html

04/08 11:32, 1年前 , 1F
大師
04/08 11:32, 1F

04/08 11:33, 1年前 , 2F
噓三小 我等等就去把你噓噓的地方剪掉
04/08 11:33, 2F

04/08 11:35, 1年前 , 3F
噓你怎麼了
04/08 11:35, 3F

04/08 11:36, 1年前 , 4F
你自己剪掉就好 你只需要大號的地方
04/08 11:36, 4F

04/08 11:37, 1年前 , 5F
快滾回花蓮
04/08 11:37, 5F

04/08 11:41, 1年前 , 6F
哭了 你們怎麼這麼凶 你們的性癖就是對喜歡的人噓噓吧
04/08 11:41, 6F

04/08 11:59, 1年前 , 7F
存7800
04/08 11:59, 7F
文章代碼(AID): #1c4sL7-4 (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1c4sL7-4 (Marginalman)