O(K+N) 3 ms Java Solution


  • 0
    X
    public int[] getModifiedArray(int length, int[][] updates) {
        int[] res = new int[length+1];
        for(int[] update:updates){
            res[update[0]]+=update[2];
            res[update[1]+1]-=update[2];
        }
        int len=res.length;
        for(int i=1;i<len;i++) res[i]+=res[i-1];
        return Arrays.copyOfRange(res, 0, len-1);
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.