```
public class Solution {
public int maxProfit(int[] prices) {
if(prices == null || prices.length < 2)
return 0;
int maxProfit = 0;
int bought = prices[0];
for(int p: prices)
{
if(p > bought)
maxProfit += p - bought;
bought = p;
}
return maxProfit;
}
}
```

Super concise. As long as the next day's price is higher than today's price, you buy it and sell it the next day. For sequence like 1 , 5, 9, we buy one day one, sell on day two, then buy on day 2 and then buy on day3. It is true that we cannot buy and sell on the same day. However the result is the same to buy on day one and sell on day three.

So, to sum up, you buy it as long as the price today is lower than yesterday's price, and sell it as long as the next day's price is higher than today's price.