Leetcode122. Best Time to Buy and Sell Stock II
来源:互联网 发布:战舰世界详细数据 编辑:程序博客网 时间:2024/05/19 12:41
Leetcode122. Best Time to Buy and Sell Stock II:
给你每天的股票价格,可以多次交易,求最大收益,当然前提是先买后卖!
Say you have an array for which the ith element is the price of a given stock on day i.
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).
Subscribe to see which companies asked this question
C++代码:
class Solution {public: int maxProfit(vector<int>& prices) { int Maxsum = 0; int n = prices.size(); int i = 0; if (n <= 1) return 0; for (i = 1; i<n; i++) { Maxsum += (prices[i] - prices[i - 1])>0 ? (prices[i] - prices[i - 1]) : 0; } return Maxsum; }};
0 0
- leetcode122---Best Time to Buy and Sell Stock II
- LeetCode122:Best Time to Buy and Sell Stock II
- leetcode122 Best Time to Buy and Sell Stock II
- LeetCode122. Best Time to Buy and Sell Stock II
- leetcode122 Best Time to Buy and Sell Stock II
- Leetcode122. Best Time to Buy and Sell Stock II
- leetcode122.[DP] Best Time to Buy and Sell Stock II
- LeetCode122—Best Time to Buy and Sell Stock II
- leetcode122. Best Time to Buy and Sell Stock II
- leetcode122~Best Time to Buy and Sell Stock II
- LeetCode122. Best Time to Buy and Sell Stock II题解
- LeetCode122 Best Time to Buy and Sell Stock II
- Leetcode122. Best Time to Buy and Sell Stock II
- LeetCode122. Best Time to Buy and Sell Stock II
- LeetCode122. Best Time to Buy and Sell Stock II
- LeetCode122. Best Time to Buy and Sell Stock II
- LeetCode122——Best Time to Buy and Sell Stock II
- Leetcode122 - Best Time to Buy and Sell Stock II (dp)
- LA 2191(p247)----Potentiometers
- 总结&备忘:ShareSDK中微信分享报-6错误
- Codeforces Round #345 (Div. 2)
- java多线程断点下载
- 数列排序(选择排序法和冒泡排序法)
- Leetcode122. Best Time to Buy and Sell Stock II
- 日语2
- uva10066 - The Twin Towers(LCS)
- Thinkpad8在Windows10下假关机的解决办法
- 【leetcode】Array——Longest Consecutive Sequence(128)
- 自己实现atof
- codeforces 607 B Zuma(区间dp)
- 重温javascript--垃圾回收机制和块级作用域
- 话说C++中的左值、纯右值、将亡值