-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
37 lines (32 loc) · 1.18 KB
/
Solution.cs
File metadata and controls
37 lines (32 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System.Text;
namespace LeetCode.Problem1700{
//1700. Number of Students Unable to Eat Lunch
//https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/
/*
You are given two integer arrays students and sandwiches where sandwiches[i] is the type of the ith sandwich in the stack
(i = 0 is the top of the stack) and students[j] is the preference of the jth student in the initial queue (j = 0
is the front of the queue). Return the number of students that are unable to eat.
*/
public class Solution {
public int CountStudents(int[] students, int[] sandwiches) {
Queue<int> stud = new Queue<int>(students);
Stack<int> sand = new Stack<int>(sandwiches.Reverse());
while (
stud.Count > 0
&&
!((stud.Contains(0) ^ stud.Contains(1))
&& sand.Peek() != stud.Peek())
)
{
var peolpe = stud.Dequeue();
var food = sand.Pop();
if (peolpe != food)
{
stud.Enqueue(peolpe);
sand.Push(food);
}
}
return stud.Count;
}
}
}