53. Maximum Subarray
2025. 10. 7. 16:10ㆍAlgorithm/Leetcode, Lintcode, HackerRank, etc.
- 목차
반응형
def maxSubArray(self, nums: List[int]) -> int:
tot = 0
mx = float('-inf')
for num in nums:
if tot + num > num:
tot += num
else:
tot = num
mx = max(mx, tot)
return mx
반응형
'Algorithm > Leetcode, Lintcode, HackerRank, etc.' 카테고리의 다른 글
3446. Sort Matrix by Diagonals (0) | 2025.10.07 |
---|---|
884. Uncommon Words from Two Sentences (0) | 2025.10.07 |
1189. Maximum Number of Balloons (0) | 2025.10.07 |
104. Maximum Depth of Binary Tree (0) | 2025.10.05 |
417. Pacific Atlantic Water Flow (0) | 2025.10.05 |