leetcode 122 Best Time to Buy and Sell Stock II
来源:互联网 发布:java中的集合是什么 编辑:程序博客网 时间:2024/06/04 17:55
Problem:
给一个数组,表示有一个物体他在第i天的价格,每天只能购买或出售一次(当天可以同时购买和出售),问最大的收益是多少?
Solution:
当第二天的钱比今天高的时候,那么我们今天买,第二天卖即可。
class Solution {public: int maxProfit(vector<int>& prices) { int ans = 0; for(int i = 1; i < prices.size(); i++) { if(prices[i] > prices[i-1]) ans += prices[i] - prices[i-1]; } return ans; }};
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
- 谷歌小程序(Android Instant Apps)和微信小程序,你更看好哪个?
- C程序设计学习笔记(完结)
- java使用webmagic实现网络爬虫功能(二)
- 工作沉浸的研究现状及展望,2016下载
- 1151. 魔板(BFS+康托展开式)
- leetcode 122 Best Time to Buy and Sell Stock II
- 将 Win32 程序移植到 Linux
- Codeforces 427C Checkposts 强连通分量(tarjan)
- 2D绘图基础——Android群英会浏览记录2
- 学习《core java》记录 -- 第三章
- String s1="AB"和String s2=new String("AB")的区别
- notes Emacs Markdown 模式简介
- Unity 及 VS2015 创建脚本时自动添加头部注释
- 深度学习入门课程学习笔记06 反向传播