본문 바로가기

IT/코딩테스트

[Leetcode] 1656. Design an Ordered Stream

728x90

https://leetcode.com/problems/design-an-ordered-stream/description/

 

LeetCode - The World's Leading Online Programming Learning Platform

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

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