Best Time to Buy and Sell Stock II - Leetcode 122 - Arrays & Strings (Python)

  Рет қаралды 3,695

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 15
@GregHogg
@GregHogg 3 ай бұрын
Master Data Structures & Algorithms for FREE at AlgoMap.io/
@paranoiak669
@paranoiak669 6 күн бұрын
My solution was this code : profit = 0 for i in range(len(prices)-1): diff = prices[i+1]-prices[i] if diff>0: profit += diff return profit No need to calculate low and high here. But as always, great video !
@thomasbooth2778
@thomasbooth2778 3 ай бұрын
Theres also a really nice greedy solution to this also. Where it mentions 'You can buy it then immediately sell it on the same day.' Was something I overlooked at the start and wrote a solution like yours. Definitely worth noting to look for small bits of info like this in problems
@JoeTan-nq4fq
@JoeTan-nq4fq 2 ай бұрын
Love your videos. Concise and easy to understand.
@RuoyanJiang
@RuoyanJiang 2 ай бұрын
Love your video, it was concise, the solution was easy to understand and definitely helped me prepare for the interview, thanks :)
@JoeTan-nq4fq
@JoeTan-nq4fq 2 ай бұрын
It would be similar that we calculate the difference of today's and y'day's price for all prices. The max profit would be the sum of all the profits (ignore the losses).
@angelomarano8458
@angelomarano8458 3 ай бұрын
love this videos, very helpfull!.
@GregHogg
@GregHogg 3 ай бұрын
Thank you!
@ambersautner
@ambersautner 3 ай бұрын
extremely thorough and easy to understand! thank you for making these videos, im planning on binging your channel lolol
@GregHogg
@GregHogg 3 ай бұрын
Binge it up at algomap.io :)
@pawelrolbiecki7813
@pawelrolbiecki7813 Ай бұрын
But you can buy and sell it the same day. So why don't we do it "scalping" way? make profit "day by day" ? It simplifies the aproach and it is fatser.
@testter-u5j
@testter-u5j Ай бұрын
Intel lol 🤣🤣
@GregHogg
@GregHogg Ай бұрын
Hahaha
Jump Game II - Leetcode 45 - Recursive Backtracking (Python)
9:37
Из какого города смотришь? 😃
00:34
МЯТНАЯ ФАНТА
Рет қаралды 2,5 МЛН
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 6 МЛН
Ice Cream or Surprise Trip Around the World?
00:31
Hungry FAM
Рет қаралды 21 МЛН
H Index - Leetcode 274 - Arrays & Strings (Python)
9:50
Greg Hogg
Рет қаралды 7 М.
Being Competent With Coding Is More Fun
11:13
TheVimeagen
Рет қаралды 116 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 147 М.
Best Time to Buy and Sell Stock III | Leetcode #123
35:40
Techdose
Рет қаралды 71 М.
Why is everyone LYING?
7:56
NeetCodeIO
Рет қаралды 349 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 687 М.
Из какого города смотришь? 😃
00:34
МЯТНАЯ ФАНТА
Рет қаралды 2,5 МЛН