Skip to content

Commit f3d7ef5

Browse files
committed
Time: 3 ms (100.00%), Space: 81.2 MB (100.00%) - LeetHub
1 parent 4ff333c commit f3d7ef5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public boolean isZeroArray(int[] nums, int[][] queries) {
3+
// Sweep Line ALgo :-
4+
int n = nums.length;
5+
6+
int[] line = new int[n+1];
7+
8+
for(int[] query : queries){
9+
line[query[0]]--;
10+
line[query[1]+1]++;
11+
}
12+
13+
for(int i=1;i<n;i++){
14+
line[i] = line[i]+line[i-1];
15+
}
16+
17+
for(int i=0;i<n;i++){
18+
nums[i] = line[i]+nums[i];
19+
if(nums[i]<0){
20+
nums[i]=0;
21+
}
22+
if(nums[i]>0){
23+
return false;
24+
}
25+
}
26+
return true;
27+
}
28+
}

0 commit comments

Comments
 (0)