[LintCode]Best Time to Buy and Sell Stock II
class Solution {
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
public int maxProfit(int[] prices) {
// 2015-09-15
if (prices == null || prices.length == 0) {
return 0;
}
int rst = 0;
for (int i = 1; i < prices.length; i++) {
int sub = prices[i] - prices[i - 1];
if (sub > 0) {
rst += sub;
}
}
return rst;
}
};