Research on the algorithm of divide and conquer the longest continuous increment subset in the search array
var cc=console
function Find_max_crossing_lenarray (A,low,mid,high) {
var max_left=mid,max_right=mid
var left_sum=1
var sum=0
for (Var i=mid;i>low;i--) {
SUM=A[I]-A[I-1]
if (sum==1) {
left_sum++
Max_left=i-1
}else{
Break
}
}
var right_sum=1
var sum=0
for (Var i=mid;iSum=a[i+1]-a[i]
if (sum==1) {
right_sum++
Max_right=i+1
}else{
Break
}
}
return [Max_left,max_right,left_sum+right_sum-1]
}
Search for the longest consecutive incremental subset across the midpoint
var arr=[13,-3,-2,-1,20,-3,-16,-23,18,20,-7,12,-5,-22,15,-4,7]
var Re=find_max_crossing_lenarray (arr,0,8,arr.length-1)
Cc.log (RE)//=>18,20,-7,12
Function Find_maximum_lenarray (a,low,high) {
if (high==low) {
return [low,high,0]
}else{
var mid= (Low+high) >>1
/*[left_low,left_high,left_sum]*/
var left=find_maximum_lenarray (a,low,mid)
/*[right_low,right_high,right_sum]*/
var right= Find_maximum_lenarray (A,mid+1,high)
/*[cross_low,cross_high,cross _sum]*/
var cross=find_max_crossing_lenarray (A,low,mid,high)
if (Left[2]>=right[2]&&left[2]>=cross[2]) {
return left
}else if (right[2]>=left[2]&&right[2]>=cross[2]) {
return right
}else if (cross[2]>=left[2]&&cross[2]>=right[2]) {
Return Cross
}
}
}
Searches for the longest contiguous increment subset in an array
var Re2=find_maximum_lenarray (arr,0,arr.length-1)
Cc.log (Re2)//=>-3,-2,-1 [1,3,3]
3. Division and Treatment study-the longest continuous increment subset in the search array