728x90
https://leetcode.com/problems/design-an-ordered-stream/description/
class OrderedStream:
def __init__(self, n: int):
self.list = [None for i in range(n + 1)]
self.key = 1
self.max = n + 1
return None
def insert(self, idKey: int, value: str) -> List[str]:
result = []
self.list[idKey] = value
for i in range(self.key, self.max):
if self.list[i] is None:
break
result.append(self.list[i])
self.key += 1
return result
# Your OrderedStream object will be instantiated and called as such:
# obj = OrderedStream(n)
# param_1 = obj.insert(idKey,value)
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 2325. Decode the Message (0) | 2024.02.21 |
---|---|
[Leetcode] 1630. Arithmetic Subarrays (0) | 2024.02.20 |
[Leetcode] 535. Encode and Decode TinyURL (0) | 2024.02.18 |
[Leetcode] 1365. How Many Numbers Are Smaller Than the Current Number (0) | 2024.02.09 |
[Leetcode] 2610. Convert an Array Into a 2D Array With Conditions (0) | 2024.02.08 |