界限问题 ++i
public class S_121 {
public int maxProfit(int[] prices) {
// 为空或者长度为零
if (prices == null || prices.length < 1) {
return 0;
}
int bene = 0;
// 上层循环 ++i 先自增
for(int i = 0;i < prices.length;++i){
for(int j = i + 1;j < prices.length;++j){
if(prices[j] - prices[i] > bene)
bene = prices[j] - prices[i];
}
}
return bene;
}
}