Leetcode: Best Time to Buy and Sell Stock II
来源:互联网 发布:淘宝旺旺mac版 编辑:程序博客网 时间:2024/06/06 06:35
http://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/
class Solution {public: int maxProfit(vector<int> &prices) { // Start typing your C/C++ solution below // DO NOT write int main() function int size=prices.size(); int profit=0; for(int i=1;i<size;i++){ if(prices[i]>prices[i-1]&&(i==(size-1)||prices[i]>=prices[i+1])){ for(int j=i-1;j>=0;j--){ if(prices[j]<prices[j+1]&&(j==0||prices[j]<=prices[j-1])){ profit+=prices[i]-prices[j]; break; } } } } return profit; }};
- [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
- C#提高知识-001:反射的应用和原理(一)
- Some English courses in Guildford
- asdasd
- LeetCode题解:Two Sum
- Use thrust reduce_by_key with raw pointers instead of device pointers
- Leetcode: Best Time to Buy and Sell Stock II
- Leetcode: Same Tree
- Leetcode: Maximum Depth of Binary Tree
- Leetcode: Reverse Integer
- Leetcode: Symmetric Tree
- Leetcode: Merge Sorted Array
- Leetcode: Climbing Stairs
- Leetcode: Remove Duplicates from Sorted List
- Leetcode: Search Insert Position