File tree Expand file tree Collapse file tree 4 files changed +27
-0
lines changed Expand file tree Collapse file tree 4 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution :
2+ def maxSubArray (self , nums : List [int ]) -> int :
3+ output = nums [0 ]
4+ max_sum = nums [0 ]
5+ for num in nums [1 :] :
6+ max_sum = max (max_sum + num , num )
7+ output = max (max_sum , output )
8+ return output
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def maxSubArray (self , nums : List [int ]) -> int :
3+ output = - inf
4+ max_sum = - inf
5+ for num in nums :
6+ max_sum = max (max_sum + num , num )
7+ output = max (max_sum , output )
8+ return output
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def maxSubArray (self , nums : List [int ]) -> int :
3+ max_sum = - inf
4+ return max ((max_sum := max (max_sum + num , num )) for num in nums )
Original file line number Diff line number Diff line change 1+ ## V1/V2
2+
3+ Standard appraoches
4+
5+ ## V3
6+
7+ Oneliner attempt to optimize since built-in functions are coded in C.
You can’t perform that action at this time.
0 commit comments