当前位置:网站首页>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
};
边栏推荐
- Teach you how to optimize SQL
- Explain AI accelerator in detail: why is this the golden age of AI accelerator?
- Redis transaction
- Design and implementation of redis 7.0 multi part AOF
- Site favorites
- [latex] production of complex tables: excel2latex and detail adjustment
- C language black Technology: Archimedes spiral! Novel, interesting, advanced~
- Backpropagation formula derivation [Li Hongyi deep learning version]
- Gee import SHP data - crop image
- [untitled] the relationship between the metauniverse and digital collections
猜你喜欢
Node write API
Setting methods, usage methods and common usage scenarios of environment variables in postman
GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day
Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website
This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
WordPress collection WordPress hang up collection plug-in
C learning notes: C foundation - Language & characteristics interpretation
Tsinghua University product: penalty gradient norm improves generalization of deep learning model
C language black Technology: Archimedes spiral! Novel, interesting, advanced~
[Yugong series] February 2022 attack and defense world advanced question misc-83 (QR easy)
随机推荐
POSTECH | option compatible reward reverse reinforcement learning
Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine
Teach you how to optimize SQL
Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
[UE4] parse JSON string
Unity knapsack system (code to center and exchange items)
Key knowledge of C language
[database I] database overview, common commands, view the table structure of 'demo data', simple query, condition query, sorting data, data processing function (single row processing function), groupi
150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan
what does ctrl + d do?
Unspeakable Prometheus monitoring practice
[untitled]
2022 registration examination for safety production management personnel of fireworks and firecracker production units and examination skills for safety production management personnel of fireworks an
GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day
Global and Chinese market of contour projectors 2022-2028: Research Report on technology, participants, trends, market size and share
Setting methods, usage methods and common usage scenarios of environment variables in postman
What are the virtual machine software? What are their respective functions?
CSCI 2134
Backpropagation formula derivation [Li Hongyi deep learning version]
JS object definition