Inscription LeetCode brush (13) - and the maximum subsequence

Topics requirements:

Given the nums an array of integers, and find a maximum of the successive sub-array (sub-array comprising a minimum element) having its maximum and returns.

Example:

Input: [-2,1, -3,4, -1,2,1, -5,4],
output: 6
Explanation: continuous subarray [4, -1,2,1], and the maximum was 6 .

answer:

(1) Direct idea 1: solving the violence, inside and outside the loop twice:

 

 

 (2) classical idea: dynamic programming: the boundary is nums [0], state transition equation is: sum = max (nums [i], sum + nums [i]); traversing, the time complexity is O (n)

 

 (3) Component Algorithm: time complexity of O (nlogn): directly on leecode editor running out, run out on IDEA, mainly around two recursive portion, a middle portion summation, as follows:

 

Guess you like

Origin www.cnblogs.com/wangjm63/p/11514773.html