121 Best Time to Buy and Sell Stock
来源:互联网 发布:闰秒 知乎 编辑:程序博客网 时间:2024/06/04 19:50
这题是看算法导论学会的。。。。
public class Solution { public int maxProfit(int[] prices) { if (prices == null || prices.length <= 1) { return 0; } int max = Integer.MIN_VALUE; int sum = 0; for (int i = 1; i < prices.length; i++) { int profit = prices[i] - prices[i - 1]; sum += profit; if (sum < 0) { sum = 0; } max = Math.max(max, sum); } return max; }}
0 0
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time To Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- JAVA 3DES加密解密
- oracle 连接 web service (利用soap_api)
- oracle 分区表的建立方法
- python codeforces 322 div2 C
- 拍摄的照片上传之后旋转如何解决?
- 121 Best Time to Buy and Sell Stock
- spring框架学习(一)
- 移动端背景图片铺满屏幕
- cx_Oracle安装
- 麦子学院cocos2d听课截图
- 10段代码打通js学习的任督二脉
- 根据文件名修改文件(创业天使-xxx 120101_超清.mp4 --> 120101-创业天使-xxx.mp4)
- getReadableDatebase() 和getwriteableDatebase()
- spring框架学习(二)依赖注入