Skip to content

Commit bcc8999

Browse files
committed
Time: 0 ms (100%), Space: 17.8 MB (63.16%) - LeetHub
1 parent f01419c commit bcc8999

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# time complexity: O(n+m)
2+
# space complexity: O(1)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def countStudents(self, students: List[int], sandwiches: List[int]) -> int:
8+
circleStudents = 0
9+
squareStudents = 0
10+
for student in students:
11+
if student == 0:
12+
circleStudents += 1
13+
else:
14+
squareStudents += 1
15+
for sandwich in sandwiches:
16+
if sandwich == 0 and circleStudents == 0:
17+
return squareStudents
18+
if sandwich == 1 and squareStudents == 0:
19+
return circleStudents
20+
if sandwich == 0:
21+
circleStudents -= 1
22+
else:
23+
squareStudents -= 1
24+
return 0
25+
26+
27+
students = [1, 1, 1, 0, 0, 1]
28+
sandwiches = [1, 0, 0, 0, 1, 1]
29+
print(Solution().countStudents(students, sandwiches))
30+
students = [1, 1, 1, 0, 0, 1]
31+
sandwiches = [1, 0, 0, 0, 1, 1]
32+
print(Solution().countStudents(students, sandwiches))

0 commit comments

Comments
 (0)