leetcode 买卖股票问题
leetcode121 Best Time to Buy and Sell Stock
说白了找到最大的两组数之差即可
class Solution {
public:
int maxProfit(vector<int>& prices) {
int m = ;
for(int i = ; i < prices.size(); i++){
for(int j = i + ; j < prices.size(); j++){
m = max(m, prices[j] - prices[i]);
}
}
return m;
}
};
leetcode122 Best Time to Buy and Sell Stock II
关键在于明白股票可以当天卖出再买进
class Solution {
public:
int maxProfit(vector<int>& prices) {
if(prices.size() == ) return ;
int m = ;
for(int i = ; i < prices.size() - ; i++){
if(prices[i] < prices[i + ]){
m += prices[i + ] - prices[i];
}
}
return m;
}
};
leetcode 买卖股票问题的更多相关文章
- LeetCode 买卖股票的最佳时机 II
给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 设计一个算法来计算你所能获取的最大利润.你可以尽可能地完成更多的交易(多次买卖一支股票). 注意:你不能同时参与多笔交易(你必须在再次 ...
- LeetCode 买卖股票的最佳时机
给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 如果你最多只允许完成一笔交易(即买入和卖出一支股票),设计一个算法来计算你所能获取的最大利润. 注意你不能在买入股票前卖出股票. 示例 ...
- leetcode题解-122买卖股票的最佳时期
题目 leetcode题解-122.买卖股票的最佳时机:https://www.yanbinghu.com/2019/03/14/30893.html 题目详情 给定一个数组,它的第 i 个元素是一支 ...
- 【Leetcode】【简单】【122. 买卖股票的最佳时机 II】【JavaScript】
题目描述 122. 买卖股票的最佳时机 II 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 设计一个算法来计算你所能获取的最大利润.你可以尽可能地完成更多的交易(多次买卖一支股票) ...
- [LeetCode] 121. Best Time to Buy and Sell Stock 买卖股票的最佳时间
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- [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] 123. Best Time to Buy and Sell Stock III 买卖股票的最佳时间 III
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] 188. Best Time to Buy and Sell Stock IV 买卖股票的最佳时间 IV
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] 309. Best Time to Buy and Sell Stock with Cooldown 买卖股票的最佳时间有冷却期
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
随机推荐
- OO第一单元总结分析
综述:本模块的内容为表达式求导,目的是通过不同项的嵌套四则运算求导这一基本思路熟悉面向对象的继承与接口机制. 一.三次作业总结分析 1.第一次作业: 1.1 作业分析 盼望着,盼望着,鸽了一年的oo终 ...
- C++标准模板库(STL)之Queue
1.Queue的常用用法 queue:队列,实现的一个先进先出的容器. 1.1.queue的定义 使用queue,首先要加头文件#include<queue>和using namespac ...
- 读《Tooth-Marked Tongue Recgnition Using Multiple Instance Learning and CNN Features》
本人 组会汇报的一篇关于齿痕舌判定的文章,贴上PPT 涉及多示例学习和神经网络方面知识. 准确率有待提高哈哈.
- docker 安装redis , 让宿主机可以访问
1, docker 拉去最新版本的redis docker pull redis #后面可以带上tag号, 默认拉取最新版本 2, docker安装redis container 安装之前去定义我们的 ...
- baidu-map
1 var map = new BMap.Map("wcp"); // 创建Map实例 2 map.centerAndZoom(new BMap.Point(9.123469591 ...
- For in + 定时器
Fon in for/in 语句用于循环对象属性. 循环中的代码每执行一次,就会对对数组的元素对象的属性进行一次操作. <p id = "demo"><p> ...
- Unity配置安卓开发环境
1. 首先要安装JDK,从网上下载即可,我用的版本如下图 注意:此时要保存JDK的路径信息,后面需要使用2. 配置环境变量,计算机右键点属性->高级->环境变量3. 在系统中新建环境变量 ...
- .net core WebApi ManualResetEvent实现并发同步
ManualResetEvent,即手动重置事件,通过信号量来判别当前线程是否应该阻塞或继续执行.使用方式与ManualResetEventSlim差不多,ManualResetEventSlim只是 ...
- js 中innerHTML,innerText,outerHTML,outerText的区别
开头说下innerText和outerText只在chrome浏览器中有效 定义和用法 innerHTML 属性设置或返回表格行的开始和结束标签之间的 HTML,包括标签. 来看代码 <!DOC ...
- rabbitmq 日志存储路径
Linux 下/var /log/rabbitmq/ windows下C:\Users\Administrator\AppData\Roaming\RabbitMQ\log