1784. Check if Binary String Has at Most One Segment of Ones (easy)
def checkOnesSegment(self, s):
return '01' not in s
855. Exam Room (medium)
class ExamRoom:
import heapq
def __init__(self, n: int):
self.heap = []
self.len = n
def seat(self) -> int:
n = len(self.heap)
# print(self.heap, n)
if n == 0:
heappush(self.heap, 0)
return 0
elif n == 1:
a, b = self.heap[0], self.len - 1 - self.heap[0]
if a > b:
heappush(self.heap, 0)
return 0
else:
heappush(self.heap, self.len - 1)
return self.len - 1
else:
dis = -1
pos = -1
for i in range(n - 1):
p = self.heap[i + 1] - self.heap[i]
if dis < p:
dis = p
pos = (self.heap[i + 1] + self.heap[i]) // 2
heappush(self.heap, pos)
print(self.heap, n)
return pos
def leave(self, p: int) -> None:
for i in range(len(self.heap)):
if self.heap[i] == p:
self.heap.pop(i)
break
print(self.heap)
# Your ExamRoom object will be instantiated and called as such:
# obj = ExamRoom(n)
# param_1 = obj.seat()
# obj.leave(p)