Download 10-week-algorithm-excercise-master/Week_06/53/maximum_subarray.py from Dorothydu/gitrepo_20: direct link, hf CLI and curl.
- Browser
- Download file 251 Bytes
-
https://huggingface.co/datasets/Dorothydu/gitrepo_20/resolve/main/10-week-algorithm-excercise-master/Week_06/53/maximum_subarray.py
- Command line
-
hf download hf://datasets/Dorothydu/gitrepo_20/10-week-algorithm-excercise-master/Week_06/53/maximum_subarray.py
-
curl -L -o maximum_subarray.py https://huggingface.co/datasets/Dorothydu/gitrepo_20/resolve/main/10-week-algorithm-excercise-master/Week_06/53/maximum_subarray.py
251 Bytes
| from typing import List | |
| class Solution: | |
| def maxSubArray(self, nums: List[int]) -> int: | |
| curr = nums[0] | |
| res = curr | |
| for n in nums[1:]: | |
| curr = n + max(0, curr) | |
| res = max(res, curr) | |
| return res | |