Title: #150 - Evaluate Reverse Polish Notation - LeetCode JavaScript Solutions
Open Graph Title: #150 - Evaluate Reverse Polish Notation - LeetCode JavaScript Solutions
X Title: #150 - Evaluate Reverse Polish Notation - LeetCode JavaScript Solutions
Description: You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation. Evaluate the expression. Ret...
Open Graph Description: You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation. Evaluate the expression. Ret...
X Description: You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation. Evaluate the expression. Ret...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/evaluate-reverse-polish-notation
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/evaluate-reverse-polish-notation","name":"#150 - Evaluate Reverse Polish Notation - LeetCode JavaScript Solutions","description":"You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation. Evaluate the expression. Ret...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {string[]} tokens\n * @return {number}\n */\nvar evalRPN = function(tokens) {\n const stack = [];\n const operators = {\n '+': (a, b) => a + b,\n '-': (a, b) => a - b,\n '*': (a, b) => a * b,\n '/': (a, b) => a / b >= 0 ? Math.floor(a / b) : Math.ceil(a / b),\n };\n\n tokens.forEach(token => {\n if (operators[token]) {\n const item = stack.pop();\n stack.push(operators[token](stack.pop(), item));\n } else {\n stack.push(Number(token));\n }\n });\n\n return stack.pop();\n};","keywords":"LeetCode 150, #150 - Evaluate Reverse Polish Notation, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/evaluate-reverse-polish-notation |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/evaluate-reverse-polish-notation/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0150-evaluate-reverse-polish-notation.js |
| Array | https://leetcodejavascript.com/tags/array |
| Math | https://leetcodejavascript.com/tags/math |
| Stack | https://leetcodejavascript.com/tags/stack |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow