leetcode-122

1
2
3
4
5
6
7
8
9
int total = 0;

//遍历所有交易日
for (int i = 0; i < prices.length - 1; i++) {
//只要是后一天比前一天贵,就卖出
if (prices[i + 1] > prices[i]) total += prices[i + 1] - prices[i];
}

return total;