leetcode 53. Maximum Subarray
2017-02-23 10:59
471 查看
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum. 最大子列和
思路:在线搜索O(n)
class Solution(object):
def maxSubArray(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
s = None;c = 0;j=0
while j<len(nums):
c+=nums[j]
if c>s or s==None:
s = c
if c<0:
c=0
j+=1
return s
思路:在线搜索O(n)
class Solution(object):
def maxSubArray(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
s = None;c = 0;j=0
while j<len(nums):
c+=nums[j]
if c>s or s==None:
s = c
if c<0:
c=0
j+=1
return s
相关文章推荐
- LeetCode 53. Maximum Subarray
- [leetcode]53. Maximum Subarray
- LeetCode - 53. Maximum Subarray
- leetcode 53. Maximum Subarray
- Leetcode-53. Maximum Subarray
- [array] leetcode - 53. Maximum Subarray - Easy
- leetcode 53. Maximum Subarray
- LeetCode 53. Maximum Subarray
- LeetCode | 53. Maximum Subarray
- [LeetCode] 53. Maximum Subarray
- LeetCode53. Maximum Subarray
- leetcode 53. Maximum Subarray
- leetcode 53. Maximum Subarray 动态规划DP + 最大子串和
- Leetcode 53. Maximum Subarray
- LeetCode 53. Maximum Subarray
- leetcode题解——53. Maximum Subarray
- LeetCode 53. Maximum Subarray
- [leetcode]53. Maximum Subarray 最大连续子串python实现【medium】
- [leetcode] 53. Maximum Subarray
- leetcode 53. Maximum Subarray