项目作者: bensonlin321

项目描述 :
53. Maximum Subarray
高级语言: C++
项目地址: git://github.com/bensonlin321/53-maximum-subarray.git
创建时间: 2020-10-18T13:34:02Z
项目社区:https://github.com/bensonlin321/53-maximum-subarray

开源协议:

下载


53-maximum-subarray

  1. Maximum Subarray
  • Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

  • Follow up: If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.

  1. Example 1:
  2. Input: nums = [-2,1,-3,4,-1,2,1,-5,4]
  3. Output: 6
  4. Explanation: [4,-1,2,1] has the largest sum = 6.
  5. Example 2:
  6. Input: nums = [1]
  7. Output: 1
  8. Example 3:
  9. Input: nums = [0]
  10. Output: 0
  11. Example 4:
  12. Input: nums = [-1]
  13. Output: -1
  14. Example 5:
  15. Input: nums = [-2147483647]
  16. Output: -2147483647