当前位置:网站首页>A wonderful time to buy and sell stocks
A wonderful time to buy and sell stocks
2022-07-01 18:34:00 【Free dreamer】
Traverse the entire array , Deviate to No i Number of hours , Before finding out i-1 The minimum number , Subtracting , Update stock profits
step
1. Create two variables , One stores stock profits , Before a storage i-1 The minimum value of
2. Traverse the entire array for comparison
class Solution {
public:
int maxProfit(vector<int>& prices) {
int res = 0,m=1e4+10;
for(int i = 0;i < prices.size(); i++){
res=max(prices[i]-m,res);
m=min(m,prices[i]);
}
return res;
}
};
边栏推荐
- Sanfeng cloud 0215 I often use
- Data query language (DQL)
- [PHP foundation] realize the connection between PHP and SQL database
- 聊聊项目经理最爱使用的工具
- Basic concepts of binary tree
- Penetration practice vulnhub range Tornado
- Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
- PIP version problems: PIP problems still occur when installing akshare and using Tsinghua source and Douban source
- Penetration practice vulnhub range Keyring
- Classpath classpath
猜你喜欢
Debiasing word embeddings | talking about word embedding and deviation removal # yyds dry goods inventory #
MySQL connection tools
The method of real-time tracking the current price of London Silver
Localization through custom services in the shuttle application
Domestic spot silver should be understood
A database editing gadget that can edit SQLite database. SQLite database replaces fields. SQL replaces all values of a field in the database
主成分之综合竞争力案例分析
Bug of QQ browser article comment: the commentator is wrong
Cassette helicopter and alternating electric field magnetic manometer DPC
[PHP foundation] realize the connection between PHP and SQL database
随机推荐
Thinkphp6 - CMS multi wechat management system source code
开发那些事儿:EasyCVR平台添加播放地址鉴权
網上股票開戶安全嗎?是否可靠?
Basic concepts of binary tree
Irradiance, Joule energy, exercise habits
Database - MySQL advanced SQL statement (I)
Operation of cmake under win
Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
期货账户的资金安全吗?怎么开户?
网上股票开户安全吗?是否可靠?
[image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter
Basic usage of shell script
When the fixed frequency artifact falls in love with multithreading | ros2 fixed frequency topic release demo
Cassette helicopter and alternating electric field magnetic manometer DPC
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
ZABBIX alarm execute remote command
The latest software scheme of the intelligent information management system of the armed police force
必看,时间序列分析
Is it safe to open a securities account? Is there any danger
The method of real-time tracking the current price of London Silver