LeetCode【122】Best Time to Buy and Sell Stock II
来源:互联网 发布:淘宝小商品拍摄技巧 编辑:程序博客网 时间:2024/06/05 17:34
/** * 题意:和121题不同的地方是可以多次买卖任意次,然后求多次买卖后最大利润 * * @auther Dennis * @date 2017/12/13 * 思想:贪心思想,最大的收益方法就是尽可能多的低入高抛,只要明天比今天价格高,就今天买,明天卖 */public class BestTimetoBuyandSellStockII { public static int maxProfit(int[] prices) { int maxProfit = 0; for (int i = 1; i < prices.length; i++) { if(prices[i]> prices[i-1]) maxProfit += prices[i]-prices[i-1]; } return maxProfit; } public static void main(String[] args) { int[] prices = new int[]{7,1,4,3,6}; System.out.println(maxProfit(prices)); }}
阅读全文
1 0
- LeetCode 122: Best Time to Buy and Sell Stock II
- LeetCode 122 Best Time to Buy and Sell Stock II
- LeetCode 122 Best Time to Buy and Sell Stock II
- LeetCode: Best Time to Buy and Sell Stock II [122]
- [leetcode 122] Best Time to Buy and Sell Stock II
- leetcode-122 Best Time to Buy and Sell Stock II
- leetcode || 122、Best Time to Buy and Sell Stock II
- LeetCode 122: Best Time to Buy and Sell Stock II
- Leetcode# 122 Best Time to Buy and Sell Stock II
- leetcode 122: Best Time to Buy and Sell Stock II
- leetCode #122 Best Time to Buy and Sell Stock II
- leetcode: (122) Best Time to Buy and Sell Stock II
- 122 Best Time to Buy and Sell Stock II [Leetcode]
- LeetCode 122: Best Time to Buy and Sell Stock II
- LeetCode 122 Best Time to Buy and Sell Stock II
- 【LEETCODE】122-Best Time to Buy and Sell Stock II
- [leetcode 122] Best Time to Buy and Sell Stock II
- 【leetcode】【122】Best Time to Buy and Sell Stock II
- 机器学习笔记(VII)线性模型(III)对数几率回归和极大似然估计
- E558: Terminal entry not found in terminfo
- 使用svn:externals建立SVN文件(夹)链接
- Mysql中分页查询两个方法比较
- 微信分享js-sdk
- LeetCode【122】Best Time to Buy and Sell Stock II
- C# 静态成员 静态方法 静态类
- Oozie介绍
- 数据类型
- Redis的持久化机制RDB与AOF
- shell 脚本编程学习(五) 输入输出重定向和环境变量
- JS中-==-与-===
- ArcGIS BLOB—大二进制类型
- 准备好智能照明2.0了吗?---凯利讯半导体