Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 54232be

Browse files
authored
Create Zero Array Transformation I.py
1 parent 7953077 commit 54232be

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎Zero Array Transformation I.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
You are given an integer array nums of length n and a 2D array queries, where queries[i] = [li, ri].
2+
3+
For each queries[i]:
4+
5+
Select a subset of indices within the range [li, ri] in nums.
6+
Decrement the values at the selected indices by 1.
7+
A Zero Array is an array where all elements are equal to 0.
8+
9+
Return true if it is possible to transform nums into a Zero Array after processing all the queries sequentially, otherwise return false.
10+
11+
12+
class Solution:
13+
def isZeroArray(self, nums: List[int], queries: List[List[int]]) -> bool:
14+
15+
pref = [0]*len(nums)
16+
for q in queries:
17+
a,b = q
18+
for i in range(a,b+1):
19+
pref[i] +=1
20+
21+
print(pref)
22+
23+
if any( p<n for n,p in zip(nums,pref)):
24+
return False
25+
26+
return True
27+
28+
29+
30+
-------------------------------------------------------------------------------------

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /