Math
1 | class Solution { |
Remarks:
- TC: $O(n)$; SC: $O(1)$
- Main Idea: When traverse each index, we consider: is it better to follow the previous ones (
currentSum + nums[i]
), or start with the new numbernums[i]
, as the ones is bigger enough? - Known as: Kadane’s Algorithm