Problem Solving with Algorithms

반응형

leetcode.com/contest/weekly-contest-215

 

Contest - LeetCode

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

1656. Design an Ordered Stream

class OrderedStream {

    String[] streamList;
    int ptr;
    
    public OrderedStream(int n) {
        streamList = new String[n];
        ptr = 0;
    }
    
    public List<String> insert(int id, String value) {
        streamList[id - 1] = value;
        
        ArrayList<String> orderedStreams = new ArrayList<String>();
        for (int i=ptr; i<streamList.length; i++) {
            if (streamList[i] == null) break;
            orderedStreams.add(streamList[i]);
            ptr++;
        }
        
        return orderedStreams;
    }
}

 

반응형
반응형

공유하기

facebook twitter kakaoTalk kakaostory naver band