当前位置:网站首页>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;
}
};边栏推荐
- [acnoi2022] color ball
- Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?
- Convert the robot's URDF file to mujoco model
- What impact will multinational encryption regulation bring to the market in 2022
- Kernel stray cat stray dog pet adoption platform H5 source code
- Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
- [2. Basics of Delphi grammar] 4 Object Pascal operators and expressions
- Length of learning and changing
- JS how to convert a string with a delimiter into an n-dimensional array
- The latest software scheme of the intelligent information management system of the armed police force
猜你喜欢

Mysql database design

Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking
![[today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out](/img/f3/20b73f3545cdd17b9fbc52bf493ab4.jpg)
[today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out

Rotation order and universal lock of unity panel

Penetration practice vulnhub range Tornado

Data warehouse (3) star model and dimension modeling of data warehouse modeling

Source code of new campus errand / campus task platform on mutual station

Bernoulli distribution (a discrete distribution)

How to retrieve the password for opening Excel files

MySQL connection tools
随机推荐
徽商期货是正规期货平台吗?在徽商期货开户安全吗?
Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?
The ultimate version of the 13th simulation of the single chip microcomputer provincial competition of the Blue Bridge Cup
Data warehouse (3) star model and dimension modeling of data warehouse modeling
To improve the efficiency of office collaboration, trackup may be the best choice
Is the fund of futures account safe? How to open an account?
Samba basic usage
Relationship between sensor size, pixel, dpi resolution, inch and millimeter
Set the style of QT property sheet control
MySQL + JSON = King fried
Single element of an ordered array
[today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out
Small exercise -- subnet division and summary
C operator overloads the query table
Operating system interview assault
Yuancosmos game farmersworld farmers world - core content of the second conference in China!
EasyCVR通过国标GB28181协议接入设备,出现设备自动拉流是什么原因?
因子分析怎么计算权重?
Redis master-slave realizes 10 second check and recovery
Yolov5 practice: teach object detection by hand