【算法题】一个数组,里面至少有个正数,求一个子集,使其和最大
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); }