leetcode---Best Time to Buy and Sell Stock II---贪心
来源:互联网 发布:淘宝代理一手货源 编辑:程序博客网 时间:2024/05/16 07:38
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) { int ans = 0; int n = prices.size(); if(n == 0) return ans; for(int i=0; i<n-1; i++) { if(prices[i+1] > prices[i]) ans += prices[i+1] - prices[i]; } return ans; }};
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
- Leetcode 贪心 Best Time to Buy and Sell Stock III
- LeetCode 121 Best Time to Buy and Sell Stock (贪心)
- [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
- 【codevs 1090】加分二叉树(记忆化搜索)
- 二级C复习13
- imageloder2
- C控制语句:分支和跳转
- include编译指令和动作指令的区别
- leetcode---Best Time to Buy and Sell Stock II---贪心
- 【BLE】-CC2541 HAL层控制LED的实验
- GNU工具链(GNU toolchain)
- ActionBar
- Laravel使用支付宝进行支付开发实例
- java中List的实现原理
- tinyxml2源码分析-2
- Mybatis 输出映射-- resultType resultMap
- 没有