Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. class Solution {
  2. public int[] getModifiedArray(int length, int[][] updates) {
  3. int[] res = new int[length];
  4. for (int[] update : updates) {
  5. int start = update[0], end = update[1] + 1, val = update[2];
  6. res[start] += val;
  7. if (end < length) {
  8. res[end] -= val;
  9. }
  10. }
  11. for (int i = 1; i < length; i++) {
  12. res[i] += res[i - 1];
  13. }
  14. return res;
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement