当前位置:网站首页>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;
}
};边栏推荐
- SCP -i private key usage
- Distributed task queue: Celery usage record
- Financial judgment questions
- [acnoi2022] color ball
- Nielseniq found that 60% of the re launched products had poor returns
- 徽商期货是正规期货平台吗?在徽商期货开户安全吗?
- Roll out! Enlightenment!
- This is the latest opportunity of the London bank trend
- A database editing gadget that can edit SQLite database. SQLite database replaces fields. SQL replaces all values of a field in the database
- C operator overloads the query table
猜你喜欢

An example of data analysis of an old swatch and an old hard disk disassembly and assembly combined with the sensor of an electromagnetic press

Cloud computing - make learning easier

Record 3 - the state machine realizes key control and measures the number of external pulses

Penetration practice vulnhub range Nemesis

LeetCode 148. Sort linked list

Basic concepts of binary tree

Work and leisure suggestions of old programmers

Domestic spot silver should be understood

What are the legal risks of NFT brought by stars such as curry and O'Neill?

How to retrieve the password for opening Excel files
随机推荐
Domestic spot silver should be understood
Record 3 - the state machine realizes key control and measures the number of external pulses
Data warehouse (3) star model and dimension modeling of data warehouse modeling
Yolov5 practice: teach object detection by hand
Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
Subnet division and summary
Mysql database design
Data query language (DQL)
[PHP foundation] realize the connection between PHP and SQL database
Debiasing word embeddings | talking about word embedding and deviation removal # yyds dry goods inventory #
Calculation of intersection of two line segments
[beauty detection artifact] come on, please show your unique skill (is this beauty worthy of the audience?)
What are the legal risks of NFT brought by stars such as curry and O'Neill?
What impact will multinational encryption regulation bring to the market in 2022
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
MySQL connection tools
What is web application security testing technology?
js如何将带有分割符的字符串转化成一个n维数组
To improve the efficiency of office collaboration, trackup may be the best choice
Opencv map reading test -- error resolution