Leetcode Best Time to Buy and Sell Stock II
来源:互联网 发布:java中的方法调用 编辑:程序博客网 时间:2024/05/09 14:38
这道题由于可以不断地买卖,所以只要当前股票价格比前一次高了就可以加到profit里面去。
#include <iostream>#include <vector>using namespace std;class Solution {public:int maxProfit(vector<int> &prices) {if (prices.size() == 0){return 0;}int profit = 0;for (int i = 1; i < prices.size(); ++i){if (prices[i] > prices[i - 1]){profit += prices[i] - prices[i - 1];}}return profit;}};int main(){std::vector<int> prices;prices.push_back(1);prices.push_back(2);Solution s;cout<<s.maxProfit(prices)<<endl;return 0;}
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
- Layers
- Leetcode Maximal Rectangle
- Visual FoxPro权威指南写作原稿及光盘下载
- Leetcode Best Time to Buy and Sell Stock
- poj 1226 Substrings
- Leetcode Best Time to Buy and Sell Stock II
- ajax get和post请求
- 《谋圣鬼谷子》杀青 郭宝昌力挺段奕宏戚薇
- 《谋圣鬼谷子》探班 戚薇版公主坦言自己像母狼
- 视频:《谋圣鬼谷子》首曝片花 戚薇称王
- 《谋圣鬼谷子》曝片花 段奕宏陷三角恋戚薇称王
- ACM 背包DP [NOIP2006]金明的预算方案(budget)
- 犯得上颠倒是非得失
- 的法规和法国海军风格和