We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 337686c commit 4a417a4Copy full SHA for 4a417a4
3355-zero-array-transformation-i/3355-zero-array-transformation-i.java
@@ -1,25 +1,23 @@
1
class Solution {
2
public boolean isZeroArray(int[] nums, int[][] queries) {
3
// Sweep Line ALgo :-
4
- int n = nums.length;
+ 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]++;
+ line[query[0]]++;
+ line[query[1]+1]--;
11
+ }
12
+
13
+ if (line[0] < nums[0]) {
14
+ return false;
15
}
16
17
for(int i=1;i<n;i++){
18
line[i] = line[i]+line[i-1];
- }
19
- for(int i=0;i<n;i++){
- nums[i] = line[i]+nums[i];
- if(nums[i]<0){
20
- nums[i]=0;
21
22
- if(nums[i]>0){
+ if(line[i]<nums[i]){
23
return false;
24
25
0 commit comments