This is the best explanation on the problem I've seen. After your explanation I was able to code it out on my own. Thank you so much.
@jamesperalta353 жыл бұрын
For 18:30, the reason it wasn't coming out correct was because the question says "The integer division should truncate toward zero." When you perform integer division, you get the floor which would result in rounding -0.333 to -1 when it should round to 0 based on the description. int() however rounds towards 0 which is why it works.
@saianishmalla26463 жыл бұрын
Thanks for explaining!
@thechunwu2 жыл бұрын
In a situation like: "14-3/2" I find the int() rounds to -2 rather than -1 because in this case its rounding down. which is a greater negative number?
@tzujuiyu3 ай бұрын
@@thechunwu -1 is greater than -2. In your example, this expression int(-3/2) should evaluate to -1. I wonder if you added an extra ''/' by chance. int(-3//2) gives you -2
@am_0x2a9 ай бұрын
Great video! A further optimization would be to eliminate the stack altogether and keep a running sum. Instead of appending to the stack, just add. Instead of popping, just keep track of the most recent value and subtract it off. Then you can save yourself the extra loop to go through and sum all the values. Specifically, it will bring storage complexity from O(n) to O(1) and reduce time by a factor of 2 (though it will still be O(n)).
@BreakthroughCreator2 жыл бұрын
this is one of the best coding teaching videos so far, nice voice, cadence, explanation, and visuals
@anoops79742 ай бұрын
Thank you Sai Anish. Great video and explanation.
@grovestreet91652 жыл бұрын
if you're indian then your accent is realy too good
@HarshitaKhazanchi10 ай бұрын
this really cleared things up!
@n.h.son19026 ай бұрын
Great visualization! It helps build my intuition a lot for this challenge. There're a couple of ways to handle the edge case about the operator == "/", one way we can think of is to take advantage of the built-in function math.floor() and math.ceil(). Cheers!
@LARamones234 жыл бұрын
Thanks for the nice explanation! Your videos are very helpful. Integer division for negative number is the issue for stack[-1] //= curr_num. For example -3//4 returns -1 in python but 3//4 returns 0. Following approach seems also to be working. if stack[-1] >=0 : stack[-1] //= curr_num else: stack[-1] = -(-stack[-1]//curr_num)
@saianishmalla26464 жыл бұрын
Glad the videos help! Thanks for explaining why int division didn't work it makes sense.
@vidyutphagetra38043 жыл бұрын
good explanation Anish
@kevinzheng5753 жыл бұрын
Nice information. Thank you!
@sugamff88254 жыл бұрын
Big fan bro ❤️
@saianishmalla26464 жыл бұрын
ayyeee thank you!!!
@ishayadav0014 жыл бұрын
Love your videos!!
@saianishmalla26464 жыл бұрын
Glad you like them!
@linli70493 жыл бұрын
Very good explanation!
@sakshiramsinghani52843 жыл бұрын
Thanks a lot! It's really helpful.
@user-kg9lm4mp8j2 жыл бұрын
//是整除,int()是取整,题目要求向0取整,整除遇到负数会出错。
@shrimpo64162 жыл бұрын
Bc int div round towards zero. So it gets weird when rounding neg num
@aminesfahani35633 жыл бұрын
thanks i want to share this code class Solution: def myPow(self, x: float, n: int) -> float: if n==0: return 1 elif n
@Chancemm4 жыл бұрын
Thank you!!
@saianishmalla26464 жыл бұрын
You're welcome !!
@diegogarcia-pl1bt2 жыл бұрын
you just stole the answer from the discussion you clearly do not understand the code
@PremPal-uy4nm Жыл бұрын
It seems he didn't explain clearly how char & operator are working together to add values in stack to make correct calculation as we move through the string. In short char is leading in for loop and operator is lagging.
@n.h.son19026 ай бұрын
@@PremPal-uy4nm if I remember it right, he did. His explanation in the visualization meant that the variable “operator” in the code is the previous operator in the illustration and the variable “char” means the current operator we are at.