当前位置:网站首页>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
};
边栏推荐
- 150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan
- (column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)
- Global and Chinese market of box seals 2022-2028: Research Report on technology, participants, trends, market size and share
- STM32 key content
- Backpropagation formula derivation [Li Hongyi deep learning version]
- Don't disagree, this is the most powerful "language" of the Internet
- [Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
- Imperial cms7.5 imitation "D9 download station" software application download website source code
- How to use websocket to realize simple chat function in C #
- Redis transaction
猜你喜欢

Lichuang EDA learning notes 14: PCB board canvas settings

長文綜述:大腦中的熵、自由能、對稱性和動力學

PHP database connection succeeded, but data cannot be inserted

Database concept and installation

Node solves cross domain problems

96% of the collected traffic is prevented by bubble mart of cloud hosting

Setting methods, usage methods and common usage scenarios of environment variables in postman

在尋求人類智能AI的過程中,Meta將賭注押向了自監督學習

Dans la recherche de l'intelligence humaine ai, Meta a misé sur l'apprentissage auto - supervisé

Record a problem that soft deletion fails due to warehouse level error
随机推荐
Setting methods, usage methods and common usage scenarios of environment variables in postman
Backpropagation formula derivation [Li Hongyi deep learning version]
Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
(column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)
PHP database connection succeeded, but data cannot be inserted
Love and self-discipline and strive to live a core life
Global and Chinese market of digital impression system 2022-2028: Research Report on technology, participants, trends, market size and share
Rhcsa day 3
Jenkins configures IP address access
The first spring of the new year | a full set of property management application templates are presented, and Bi construction is "out of the box"
Node solves cross domain problems
[Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
Problems and solutions of several concurrent scenarios of redis
This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
PID of sunflower classic
Résumé: entropie, énergie libre, symétrie et dynamique dans le cerveau
Hospital network planning and design document based on GLBP protocol + application form + task statement + opening report + interim examination + literature review + PPT + weekly progress + network to
[software implementation series] software implementation interview questions with SQL joint query diagram
Contest3145 - the 37th game of 2021 freshman individual training match_ E: Eat watermelon
Keep an IT training diary 054- opening and closing