Skip to content

Commit

Permalink
leetcode make array elems equal to zero
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatelmas committed Nov 29, 2024
1 parent c372929 commit 78f5b26
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions leetcode/algorithms/easy/make_array_elements_equal_to_zero.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import List


class Solution:
def countValidSelections(self, nums: List[int]) -> int:
s, p, r = sum(nums), 0, 0
for e in nums:
if e > 0:
p += e
s -= e
else:
if p == s:
r += 2
elif abs(p - s) == 1:
r += 1
return r

0 comments on commit 78f5b26

Please sign in to comment.