122. Best Time to Buy and Sell Stock II
来源:互联网 发布:唱给自己的歌网络战队 编辑:程序博客网 时间:2024/06/05 05:26
题目来源【Leetcode】
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).
直接上代码:
class Solution {public: int maxProfit(vector<int>& prices) { if(prices.size() == 0) return 0; int maxp = 0; for(int i = 0; i < prices.size()-1; i++){ if(prices[i] < prices[i+1]) maxp += prices[i+1]-prices[i]; } return maxp; }};
阅读全文
0 0
- 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] 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】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
- 122. Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II
- 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 122. Best Time to Buy and Sell Stock II
- leetcode 122. Best Time to Buy and Sell Stock II
- native.js 安卓自动连接制定名称和密码的wifi
- hihocoder-1526 序列的值(DP/二进制)
- 学习JPA
- 检查网络是否连接的工具类
- 将unsigned char字符串以16进制的字符串显示
- 122. Best Time to Buy and Sell Stock II
- 【openjudge】单词接龙
- Java基础(一)变量与运算
- Javascript设计模式-05-外观模式
- C++中的TYPE、DWORD与WORD
- Spring学习(三):BeanFactory和ApplicationContext
- 在简历中使用STAR法则
- 以太坊环境搭建
- gulp详细入门教程