[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;
}
};
本文介绍了一种简单的股票买卖策略,通过分析价格波动,利用LintCode平台提供的解决方案来最大化收益。该策略适用于多次买卖操作,旨在从价格涨跌中获取利润。
326

被折叠的 条评论
为什么被折叠?



