Best Time to Buy and Sell Stock II (leetcode)
来源:互联网 发布:手机编辑照片软件 编辑:程序博客网 时间:2024/05/21 11:11
Say you have an array for which the ith element is the price of a given stock on dayi.
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.empty()) {return 0;}int max_profit = 0;int len = prices.size();for (int i = 1; i < len; ++i) {if (prices[i] > prices[i - 1]) {max_profit += prices[i] - prices[i -1];}}return max_profit; }};
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
- Reverse Integer (leetcode)
- POJ2139 Fold-warshall算法
- MYSQL安装
- TCP滑动窗口协议和拥塞控制
- C语言中宏定义使用方法详解
- Best Time to Buy and Sell Stock II (leetcode)
- 易考笔记——全局变量和静态变量的区别
- HDU - 1565 方格取数(1) (DP)
- 二叉搜索树转换为有序双向链表
- 为什么两次调用同一函数, 输入相同, 输出却不同呢? (解决困扰自己好几天的问题, 还是有点激动哈, 奖励自己一顿丰厚的晚餐)
- javascript window.open详解
- OC 基础学习2
- Android消息处理机制——Looper,Handler,Message,MessageQueue
- Unique Binary Search Trees (leetcode)