53. Maximum Subarray - brute force

# brute force def maxSubArray(self, nums): global_max = [] for length in range(1, len(nums)): sums_for_this_len = [] # a list to store all max histories for start in range(0, len(nums)-length): subarr = nums[start: start + length] local_sum = sum(subarr) # get the sum of this array sums_for_this_len.append(local_sum) # store this sum in history max_curr = max(sums_for_this_len) # get the maximum for this length global_max.append(max_curr) return max(global_max)
180823 - brute force solution.

1 Response

Error:
- Not clear about how to use range() statement. Especially the upper bound.
- Not clear how list indexing behaves when near the upper bound.

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.