当前位置:网站首页>Leecode 122. Zuijia timing of buying and selling stocks ②
Leecode 122. Zuijia timing of buying and selling stocks ②
2022-07-04 03:10:00 【Attacking-Coder】
Vision is limited to the present and the next As long as the stock rises, buy it immediately and then sell it directly , Then look back one space As long as the current is lower than the latter ( Can make money ) Buy and sell immediately This has been making money
var maxProfit = function(prices) {
// Vision is limited to the present and the next As long as the stock rises, buy it immediately and then sell it directly , Then look back one space As long as the current is lower than the latter ( Can make money ) Buy and sell immediately This has been making money
let res = 0
for(let i =1;i<prices.length;i++){
if(prices[i-1]<prices[i]){
res+=prices[i]-prices[i-1]
}
}
return res
};
边栏推荐
- 中電資訊-信貸業務數字化轉型如何從星空到指尖?
- I stepped on a foundation pit today
- 1day vulnerability pushback skills practice (3)
- Libcblas appears when installing opencv import CV2 so. 3:cannot open shared object file:NO such file or directory
- C learning notes: C foundation - Language & characteristics interpretation
- MySQL workbench use
- PTA tiantisai l1-079 tiantisai's kindness (20 points) detailed explanation
- Career development direction
- SQL injection (1) -- determine whether there are SQL injection vulnerabilities
- Optimization theory: definition of convex function + generalized convex function
猜你喜欢

Li Chuang EDA learning notes 13: electrical network for drawing schematic diagram

AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
![Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine](/img/3a/cf6285ae1c01bda42874eeca9fe5b1.jpg)
Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine

Cache general management class + cache httpcontext Current. Cache and httpruntime Differences between caches
![[software implementation series] software implementation interview questions with SQL joint query diagram](/img/8b/8718fea82f83a6169ea5d8c2e5b645.jpg)
[software implementation series] software implementation interview questions with SQL joint query diagram

C language black Technology: Archimedes spiral! Novel, interesting, advanced~

Buuctf QR code

Zblog collection plug-in does not need authorization to stay away from the cracked version of zblog

What is the difference between enterprise wechat applet and wechat applet

Setting methods, usage methods and common usage scenarios of environment variables in postman
随机推荐
PHP database connection succeeded, but data cannot be inserted
Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
[software implementation series] software implementation interview questions with SQL joint query diagram
Contest3145 - the 37th game of 2021 freshman individual training match_ J: Eat radish
ZABBIX API batch delete a template of the host
WP collection plug-in free WordPress collection hang up plug-in
WordPress collection WordPress hang up collection plug-in
Latex tips slash \backslash
3D game modeling is in full swing. Are you still confused about the future?
Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website
Baijia forum the founding of the Eastern Han Dynasty
AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
Site favorites
C # learning notes: structure of CS documents
Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami
[latex] production of complex tables: excel2latex and detail adjustment
Unity controls the selection of the previous and next characters
Setting methods, usage methods and common usage scenarios of environment variables in postman
(column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)
A brief talk on professional modeler: the prospect and professional development of 3D game modeling industry in China