dynamic programming:find max subarray

Posted on 2017-06-02 19:24  Wujunde  阅读(146)  评论(0编辑  收藏  举报

public static mark dynway( ) //put or pop the books into the basket,mark the highest recorder
{
int Sum,Max;
int lom = -1;
int him = -1;
boolean star = true;
Sum = Max =0;
for(int j = 0;j < array.length;j++)
{
Sum += array[j];

if(Sum > Max){
Max = Sum;
if(star == true){
lom = j;
him = j;
star = false;
}
else{
him = j;
}

}
else if(Sum < 0){
Sum = 0;
star = true;}
}
return new mark(lom,him,Max);
}