Super Easy Java Solution


  • 0
    public int[] getModifiedArray(int length, int[][] updates) {
            int[] inc = new int[length];
            for (int[] up : updates) {
                inc[up[0]] += up[2]; // start pos, +val
                if (up[1] < length - 1) inc[up[1] + 1] += -up[2]; // end pos, -val
            }
            // increase from start to end, 
            for (int i = 1; i < length; i++) {
                inc[i] += inc[i - 1];
            }
            return inc;
        }
    

Log in to reply
 

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