您的位置:首页 > 其它

Best Time to Buy and Sell Stock

2015-06-09 12:11 302 查看
public class Solution {
public int maxProfit(int[] prices) {
if (prices == null || prices.length == 0) {
return 0;
}
int low = Integer.MAX_VALUE;
int profits = 0;
for (int i = 0; i < prices.length; i++) {
low = prices[i] < low ? prices[i] : low;
profits = (prices[i] - low) > profits ? (prices[i] - low) : profits;
}
return profits;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  DP