Leetcode 122 Best Time to Buy and Sell Stock II
来源:互联网 发布:手机淘宝领天猫积分 编辑:程序博客网 时间:2024/06/05 05:06
Leetcode 122 Best Time to Buy and Sell Stock II
/* * 一有获利空间就进行买卖 * 也可以理解成,在递减序列的最后一个点买入,然后在递增序列的第一个点卖出 * 例:1 3 5 4 3 1 6 7 8 * maxprofit = 3-1 + 5-3 + 6-1 +7-6 + 8-7 *///为121题的思路所局限,想复杂了……class Solution {public: int maxProfit(vector<int>& prices) { int maxprofit = 0; for(int i = 1;i < prices.size();i ++) { if(prices[i] > prices[i - 1]) { int diff = prices[i] - prices[i-1]; maxprofit += diff; } } return maxprofit; }};
阅读全文
0 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
- 【Leetcode】【python】Permutations
- 模拟-Codeforces 777C
- 通过spring boot构建solr查询实例
- 仿真三件套
- 克拉美罗下界 CRLB的计算
- Leetcode 122 Best Time to Buy and Sell Stock II
- linux下动态库(共享库)
- 使用foreach操作数组
- HDU 5977 树的分治+子集枚举
- 1560 扔人游戏
- Leetcode 349 Intersection of Two Arrays
- 查看linux中的TCP连接数
- 地图集web项目_技术学习(一)_前后端数据传输(ajax)
- Leetcode 350 Intersection of Two Arrays II