알고리즘/LeetCode

[LeetCode/리트코드] #1413. Minimum Value to Get Positive Step by Step Sum [Prefix Sum/파이썬/python]

https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum/

 

Minimum Value to Get Positive Step by Step Sum - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

class Solution:
    def minStartValue(self, nums: List[int]) -> int:
        start=1
        
        while True:
            total = start
            is_valid = True
            
            for i in nums:
                total += i
                
                if total < 1:
                    is_valid = False
                    break
                    
            if is_valid:
                return start
            else:
                start+=1