【leetcode】122.Best Time to Buy and Sell Stock II(股票问题)
class Solution {
public:
int maxProfit(vector<int>& prices) {
//经典动态规划
//如何表示当天进行的交易
// 注意一点为啥是这个顺序
int a_i0=0; //无股票
int a_i1=INT_MIN; //有股票
for(auto pp:prices){
a_i0=max(a_i0,a_i1+pp);
a_i1=max(a_i1,a_i0-pp);
}
return a_i0;
}
};
【leetcode】122.Best Time to Buy and Sell Stock II(股票问题)的更多相关文章
- 31. leetcode 122. Best Time to Buy and Sell Stock II
122. Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price ...
- [LeetCode] 122. Best Time to Buy and Sell Stock II 买卖股票的最佳时间 II
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- LeetCode 122. Best Time to Buy and Sell Stock II (stock problem)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- LeetCode 122. Best Time to Buy and Sell Stock II (买卖股票的最好时机之二)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- leetcode 122. Best Time to Buy and Sell Stock II ----- java
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- Java [Leetcode 122]Best Time to Buy and Sell Stock II
题目描述: Say you have an array for which the ith element is the price of a given stock on day i. Design ...
- LeetCode 122 Best Time to Buy and Sell Stock II 解题报告
题目要求 Say you have an array for which the ith element is the price of a given stock on day i. Design ...
- [leetcode]122. Best Time to Buy and Sell Stock II 最佳炒股时机之二
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- Java for LeetCode 122 Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- LeetCode 122 Best Time to Buy and Sell Stock II(股票买入卖出的最佳时间 II)
翻译 话说你有一个数组,当中第i个元素表示第i天的股票价格. 设计一个算法以找到最大利润. 你能够尽可能多的进行交易(比如.多次买入卖出股票). 然而,你不能在同一时间来多次交易. (比如.你必须在下 ...
随机推荐
- 如何选择普通索引和唯一索引《死磕MySQL系列 五》
系列文章 一.原来一条select语句在MySQL是这样执行的<死磕MySQL系列 一> 二.一生挚友redo log.binlog<死磕MySQL系列 二> 三.MySQL强 ...
- win10+MX350显卡+CUDA10.2+PyTorch 安装过程记录 深度学习环境配置
https://blog.csdn.net/m0_37867091/article/details/105788637
- 【Java】IO流
File类 介绍 File类的一个对象,代表一个文件或一个文件目录 File类声明在java.io包下 File类中涉及关于文件或文件目录的创建.删除.重命名.修改时间.文件大小等方法,并未涉及到写入 ...
- CommonJS与ES6 Module的使用与区别
CommonJS与ES6 Module的使用与区别 1. CommonJS 1.1 导出 1.2 导入 2. ES6 Module 2.1 导出 2.2 导入 3. CommonJS 与 ES6 Mo ...
- cmd命令配置MySQL
当安装完MySql后,每次windows启动的时候都会将MySql服务启动起来. 如果是winxp则不需要使用管理员权限既可以很简单的打开和关闭,具体在cmd中敲入命令: 1.启动MySql服务: n ...
- [luogu7418]Counting Graphs P
参考[luogu7417],同样求出最短路,得到二元组$(x,y)$并排序,记$tot_{(x,y)}$为$(x,y)$的数量 其中所给的两个条件,即分别要求: 1.$(x,y)$只能和$(x\pm ...
- [bzoj5511]大中锋的游乐场
记可乐为1,汉堡为-1,即求过程中绝对值不超过k的最短路. 然后发现k的范围仅为10,也就是说过程中合法的值仅有21种,因此跑一遍dij或spfa(嘿嘿嘿)即可. 1 #include<bits ...
- 通过 for 循环,比较 Python 与 Ruby 编程思想的差别
作者:Doug Turnbull 译者:豌豆花下猫@Python猫 原文:https://softwaredoug.com/blog/2021/11/12/ruby-vs-python-for-loo ...
- 【Tool】JDK8 安装
JDK8 2019-07-26 14:05:21 by冲冲 1. 下载 通常前往官网 https://www.oracle.com/technetwork/java/javase/download ...
- 我的获奖记录及 Important Dates in OI
逊逊的获奖记录/ruo(真的没拿过啥奖,并且大部分都集中在初三阶段,即 2020-2021 赛季): NOIP2018 pj,1=,无游记 CSP-S2019,1=,无游记 APIO2020,Ag,游 ...