【算法题】一个数组,里面至少有个正数,子集,使其和最大

【算法题】一个数组,里面至少有个正数,求一个子集,使其和最大void max(int[] x){ int maxendinghere0int m

【算法题】一个数组,里面至少有个正数,求一个子集,使其和最大

 void max(int[] x){ int maxendinghere=0;         int maxsofar=0;         int l=0,u=0;//新数组的下界与上界       for (int j = 0; j < x.length; j++) {       if(maxendinghere+x[j]>0){            maxendinghere=maxendinghere+x[j];       }else{       l=j+1;       maxendinghere=0;       }             if(maxsofar<maxendinghere){       maxsofar=maxendinghere;       u=j;       }              }       System.out.println(l);             System.out.println(u); }

参考编程珠玑,并修改