作者oinishere (是oin捏)
看板Marginalman
標題Re: [閒聊] 每日leetcode
時間Mon Apr 8 11:32:21 2024
※ 引述 《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
噓 JIWP: 大師 04/08 11:32
→ oinishere: 噓三小 我等等就去把你噓噓的地方剪掉 04/08 11:33
噓 JIWP: 噓你怎麼了 04/08 11:35
噓 amsmsk: 你自己剪掉就好 你只需要大號的地方 04/08 11:36
噓 JIWP: 快滾回花蓮 04/08 11:37
→ oinishere: 哭了 你們怎麼這麼凶 你們的性癖就是對喜歡的人噓噓吧 04/08 11:41
→ Rushia: 存7800 04/08 11:59