Best Time to Buy and Sell Stock II
来源:互联网 发布:网络机顶盒 编辑:程序博客网 时间:2024/06/03 20: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 res = 0; int n = prices.size(); for (int i = 0; i < n - 1; i++) { if (prices[i] < prices[i + 1]) { res += prices[i + 1] - prices[i]; } } return res; }};
阅读全文
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
- 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
- Best Time to Buy and Sell Stock II
- 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
- Best Time to Buy and Sell Stock II
- 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
- Echart折线图 Sql总结
- [BZOJ3594]二维树状数组优化DP
- Android学习-Fragment(上)
- 【OpenCV学习笔记】1:配置开发环境
- linux 安装python-opencv
- Best Time to Buy and Sell Stock II
- 【面试题】Java三大特性封装继承多态总结
- STC15系列单片机-PWM模块
- 事务的ACID和四个隔离级别
- dockerhub 账号开通
- IDEA搭建的maven项目无SRC目录
- 欢迎使用CSDN-markdown编辑器
- 重拾Java--功底篇之String
- [设计]策略模式