Re: [閒聊] 每日leetcode已回收
※ 引述 《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
04/08 11:59, 7F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 104 之 1548 篇):