Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
For example, given the array [-2,1,-3,4,-1,2,1,-5,4],
the contiguous subarray [4,-1,2,1] has the largest sum = 6.
穷举法 时间复杂度O(N3)
1 | int solution(int a[], int N) { |
穷举法优化冗余的求和步骤 时间复杂度O(N2)
1 | int solution(int a[], int N) { |
贪心法 时间复杂度O(N)
1 | int solution(int a[], int N) { |