[Algorithm] 10 week(3.14 ~ 3.20) 1/3

Dev_min·2022년 3월 15일
0

algorithm

목록 보기
32/157

1656. Design an Ordered Stream

var OrderedStream = function(n) {
    this.stream = new Array(n + 1);
    this.pointer = 1;
};


OrderedStream.prototype.insert = function(idKey, value) {
    this.stream[idKey] = value;
    
    const result = [];
    
    while (this.stream[this.pointer] != null) {
        result.push(this.stream[this.pointer]);
        this.pointer++;
    }
    
    return result;
};
profile
TIL record

0개의 댓글