-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderedStream.py
More file actions
30 lines (22 loc) · 916 Bytes
/
OrderedStream.py
File metadata and controls
30 lines (22 loc) · 916 Bytes
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
# problem:https://leetcode.com/problems/design-an-ordered-stream/submissions/
# Runtime: 316 ms, faster than 50.00% of Python3 online submissions for Design an Ordered Stream.
# Memory Usage: 15 MB, less than 100.00% of Python3 online submissions for Design an Ordered Stream.
from typing import List
class OrderedStream:
def __init__(self, n: int):
self.strings = [None] * (n + 1)
self.indexInsert = 1
def insert(self, id: int, value: str) -> List[str]:
self.strings[id] = value
answer = []
for string in self.strings[self.indexInsert:]:
if string == None:
break
else:
answer.append(string)
if answer:
self.indexInsert += len(answer)
return answer
# Your OrderedStream object will be instantiated and called as such:
# obj = OrderedStream(n)
# param_1 = obj.insert(id,value)