Leetcode Best Time to Buy and Sell Stock II
来源:互联网 发布:美国私立高中排名知乎 编辑:程序博客网 时间:2024/05/21 14:53
Say you have an array for which the ith element is the price of a given stock on dayi.
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
代码如下:
class Solution {public: int maxProfit(vector<int>& prices) { int sum=0; if(prices.empty()) return sum; for(int i=0;i<prices.size()-1;i++) { if(prices[i+1] > prices[i]) sum += prices[i+1]-prices[i]; } return sum; }};
阅读全文
0 0
- [LeetCode]Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock II
- Leetcode: Best Time to Buy and Sell Stock II
- [Leetcode] Best Time to Buy and Sell Stock II
- LeetCode : Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock II
- [LeetCode] Best Time to Buy and Sell Stock II
- leetcode 61: Best Time to Buy and Sell Stock II
- [LeetCode] Best time to buy and sell a stock II
- 【leetcode】Best Time to Buy and Sell Stock II
- LeetCode - Best Time to Buy and Sell Stock II
- LeetCode之Best Time to Buy and Sell Stock II
- [LeetCode]Best Time to Buy and Sell Stock II
- [Leetcode]Best Time to Buy and Sell Stock II
- [leetcode]Best Time to Buy and Sell Stock II
- [LeetCode] Best Time to Buy and Sell Stock II
- LeetCode-Best Time to Buy and Sell Stock II
- [leetcode] Best Time to Buy and Sell Stock II
- Attribute 和 Parameter 的区别
- Jenkins之源码管理
- JDBC练习 模拟转账事件
- swapin的现象
- iOS持久化Core Data之二 托管对象模型的迁移
- Leetcode Best Time to Buy and Sell Stock II
- #、##和__VA_ARGS__
- 如何给recyclerView瀑布流设置均等间距
- asp.net项目中通过Web.config配置文件及文件夹的访问权限!
- 基于容器服务的持续集成与云端交付(一)- 交付之禅
- maven打包的时候不打包test里的内容
- WindowManager$BadTokenException: Unable to add window — token android.os.BinderProxy@465 is not vali
- Insall Maven in Eclipse
- extern-在整个工程文件中使用同一个变量的方法