Best Time to Buy and Sell Stock II [LeetCode]
2024-08-29 05:38:37
Problem Description: http://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/
Basic idea: from code below, it seems super easy. But intuitively, we may use one more variable "tmp_max_profit" to record every times we get the max profit.
class Solution {
public:
int maxProfit(vector<int> &prices) {
// Note: The Solution object is instantiated only once and is reused by each test case.
int max_profit = ;
for(int i = ; i < prices.size(); i ++) {
if(i + >= prices.size())
break; if(prices[i + ] > prices[i])
max_profit += prices[i + ] - prices[i];
} return max_profit;
}
};
最新文章
- C/C++ Memory Layout
- 微信小程序购物商城系统开发系列-目录结构
- 文本深度表示模型Word2Vec
- 二、verilogHDL行为描述建模
- Redis操作的封装类
- BOOTCAMP版本适配机型表
- 20151216JqueryUI---dialog代码备份
- json对象的处理
- MFC窗口风格 WS_style/WS_EX_style(超详细)
- appendGrid的使用
- iOS中有关配置 Apache 服务器的详细步骤
- javascript 学习随笔3
- react学习01
- [LeetCode] 动态规划入门题目
- 【mongodb系统学习之十一】mongodb删除数据
- 071、如何定制calico网络的IP池(2019-04-16 周二)
- JS制作蔡徐坤打篮球小游戏(鸡你太美?)
- 为django项目配置celery的后台启动
- [转]https://www.jianshu.com/p/06443248f4d8
- SQL记录-资源正忙online或nowait
热门文章
- Lucky String
- System.MissingMethodException: 找不到方法:
- LINUX DIFF命令详解
- [JAVA设计模式]第一部分:接口、抽象类、设计原则
- 8.mybatis动态SQL模糊查询 (多参数查询,使用parameterType)
- python_way,day4 内置函数(callable,chr,随机验证码,ord),装饰器
- STORM_0004_windows下zookeeper的伪集群的搭建
- 问题: unrecognized selector sent to class 0x10affab20
- Intel微处理器学习笔记(五) 中断
- Scrum Meeting---Eight(2015-11-3)