Evaluate Reverse Polish Notation (RPN) - Leetcode 150 - Stacks (Python)

  Рет қаралды 4,220

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 16
@GregHogg
@GregHogg 6 ай бұрын
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@masemark87
@masemark87 11 ай бұрын
Best channel I’ve discovered this year! Great content, thank you
@badrlakhal5440
@badrlakhal5440 5 ай бұрын
Pay attention, in Python 2, the / operator performs integer division, and rounds towards negative infinity. So 6/-132 gives -1, and of course int(6/-132) also gives -1. In Python 3, the / operator performs float division, so 6/-132 is -0.045. Then the int function truncates decimals, so int(6/-132) is 0.
@JoeTan-nq4fq
@JoeTan-nq4fq 3 ай бұрын
Using eval() for shorter code stack = [] # stack contains strings for c in tokens: if c in '+-*/': b, a = stack.pop(), stack.pop() stack.append(str(int(eval(a + c + b)))) else: stack.append(c) return int(stack[0])
@ThePersopolis
@ThePersopolis 11 ай бұрын
Could you not use stk.append( int(a / b) ) for division instead of the if/else and use of ceil and floor?
@chucksneedmoreland
@chucksneedmoreland 4 ай бұрын
I didnt know int() would do all that for you
@yugaank100
@yugaank100 3 ай бұрын
you can, it works
@Sanu-k5c
@Sanu-k5c Ай бұрын
Hello there, when putting the condition for the token being a number in the if and it being an operator in the else part, why was there a problem with the pop() statement, error said as "pop from an empty list", ? Has it got something to do with the interpreter ? Although it works fine in vs code
@mohitsonwane7031
@mohitsonwane7031 6 ай бұрын
I feel that this statement in the question is the most important. "The division between two integers always truncates toward zero."
@AliShahid-cp6bz
@AliShahid-cp6bz 7 ай бұрын
Great content and dedication.
@saleheen12
@saleheen12 3 ай бұрын
Ceil and floor giving error in leetcode although in my local compiler the output is correct. Try this instead: int(float(a)/b)
@haribshahbaz1237
@haribshahbaz1237 3 ай бұрын
or just simply int(a / b). a / b already gives us a float, therefore converting a to float explicitly is not required.
@anirbandas12
@anirbandas12 11 ай бұрын
For js/ ts ceil doesn't work i think i had to use trunc ..
@VitaliyBorisok
@VitaliyBorisok 5 ай бұрын
Noticed that in Java implementation you also used ceil and floor. But it is redundant for integer division. It always drops the part after dot.
@moonlight-td8ed
@moonlight-td8ed 6 ай бұрын
or we can just append int(a/b)
Daily Temperatures - Leetcode 739 - Stacks (Python)
12:35
Greg Hogg
Рет қаралды 10 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
Evaluate Reverse Polish Notation - Leetcode 150 - Python
9:20
Stacks & Queues - DSA Course in Python Lecture 5
14:58
Greg Hogg
Рет қаралды 18 М.
No Sound Leetcode 710: Random Pick with Blacklist
1:40
ExtremeProgrammer
Рет қаралды 4
Koko Eating Bananas - Leetcode 875 - Binary Search (Python)
13:34
Min Stack - Leetcode 155 - Stacks (Python)
8:01
Greg Hogg
Рет қаралды 5 М.
Number of Islands - Leetcode 200 - Graphs (Python)
11:01
Greg Hogg
Рет қаралды 15 М.
How DeepSeek AI Helped Me Create Maps Effortlessly
9:49
GeoDelta Labs
Рет қаралды 808 М.
LeetCode Interview Problem - Reverse Polish Notation
7:12
Keep On Coding
Рет қаралды 12 М.
Reverse Polish Notation Using Stacks
16:57
Erb Computer Science
Рет қаралды 31 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН