{"id":1248,"date":"2021-09-07T01:11:16","date_gmt":"2021-09-07T01:11:16","guid":{"rendered":"http:\/\/feellikelearning.com\/?p=1248"},"modified":"2022-07-06T16:29:30","modified_gmt":"2022-07-06T16:29:30","slug":"leetcode-150-evaluate-reverse-polish-notation","status":"publish","type":"post","link":"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/","title":{"rendered":"\u7b97\u6cd5\u7ec3\u4e60 \u529b\u6263 150. Evaluate Reverse Polish Notation"},"content":{"rendered":"\n<h2>\u95ee\u9898\u603b\u7ed3<\/h2>\n\n\n\n<p>\u8fd9\u9898\u6bd4\u8f83\u7b80\u5355\uff0c\u5982\u679c\u5b66\u8fc7computer architecture\uff0c\u8fd9\u4e2aReverse Polish Notation (RPN)\u57fa\u672c\u5c31\u662f\u4e2astack machine\u3002\u5f88\u50cf\u6c47\u7f16\u8bed\u8a00\u3002\u7528stack\u5c31\u53ef\u4ee5\u89e3\u51b3\u3002<\/p>\n\n\n\n<h2>\u5751<\/h2>\n\n\n\n<p>\u9664\u6cd5\u8981\u6c42<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>that division between two integers should truncate toward zero.<\/p><\/blockquote>\n\n\n\n<p>\u6d4b\u8bd5\u6570\u636e\u91cc\u9762\u6709\u8d1f\u6570, python\u91cc\u9762\u6574\u6570\u9664\u6cd5\u7ed3\u679c\u5982\u679c\u662f\u5c0f\u6570\uff0c\u7ea6\u6210\u6574\u6570\u540e\u662f\u5f80\u5c0f\u7684\u65b9\u5411\u7ea6\u7684\u3002\u6bd4\u5982-0.4\u4f1a\u53d8\u6210-1\uff0c\u9898\u76ee\u8981\u6c42\u5f800\u7ea6\uff0c\u4e5f\u5c31\u662f-0.4\u53d8\u62100\u3002\u7528int(a\/b)\u53ef\u89e3\u51b3\u3002\u4e00\u4e2a\u51b7\u95e8\u77e5\u8bc6\u3002<\/p>\n\n\n\n<p>Python\u89e3\u6cd5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def evalRPN(self, tokens: List&#91;str]) -> int:\n        stack = &#91;]\n        ops = {'+', '-', '*', '\/'}\n        for token in tokens:\n            if token not in ops:\n                stack.append(int(token))\n            else:\n                op = token\n                num2 = stack.pop()\n                num1 = stack.pop()\n                res = self.evalSimple(num1, num2, op)\n                stack.append(res)\n        \n        return stack.pop()\n                \n    def evalSimple(self, num1, num2, op):\n        if op == '+':\n            return num1 + num2\n        elif op == '-':\n            return num1 - num2\n        elif op == '*':\n            return num1 * num2\n        elif op == '\/':\n            return int(num1 \/ num2)    <\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\u603b\u7ed3 \u8fd9\u9898\u6bd4\u8f83\u7b80\u5355\uff0c\u5982\u679c\u5b66\u8fc7computer architecture\uff0c\u8fd9\u4e2aReverse Polish Notation (RPN)\u57fa\u672c\u5c31\u662f\u4e2astack machine\u3002\u5f88\u50cf\u6c47\u7f16\u8bed\u8a00\u3002\u7528stack\u5c31\u53ef\u4ee5\u89e3\u51b3\u3002 \u5751 \u9664\u6cd5\u8981\u6c42 that division between two integers should truncate toward zero. \u6d4b\u8bd5\u6570\u636e\u91cc\u9762\u6709\u8d1f\u6570, python\u91cc\u9762\u6574\u6570\u9664\u6cd5\u7ed3\u679c\u5982\u679c\u662f\u5c0f\u6570\uff0c\u7ea6\u6210\u6574\u6570\u540e\u662f\u5f80\u5c0f\u7684\u65b9\u5411\u7ea6\u7684\u3002\u6bd4\u5982-0.4\u4f1a\u53d8\u6210-1\uff0c\u9898\u76ee\u8981\u6c42\u5f800\u7ea6\uff0c\u4e5f\u5c31\u662f-0.4\u53d8\u62100\u3002\u7528int(a\/b)\u53ef\u89e3\u51b3\u3002\u4e00\u4e2a\u51b7\u95e8\u77e5\u8bc6\u3002 Python\u89e3\u6cd5<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[19,15,3],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7b97\u6cd5\u7ec3\u4e60 \u529b\u6263 150. Evaluate Reverse Polish Notation | Feel Like Learning<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7b97\u6cd5\u7ec3\u4e60 \u529b\u6263 150. Evaluate Reverse Polish Notation | Feel Like Learning\" \/>\n<meta property=\"og:description\" content=\"\u95ee\u9898\u603b\u7ed3 \u8fd9\u9898\u6bd4\u8f83\u7b80\u5355\uff0c\u5982\u679c\u5b66\u8fc7computer architecture\uff0c\u8fd9\u4e2aReverse Polish Notation (RPN)\u57fa\u672c\u5c31\u662f\u4e2astack machine\u3002\u5f88\u50cf\u6c47\u7f16\u8bed\u8a00\u3002\u7528stack\u5c31\u53ef\u4ee5\u89e3\u51b3\u3002 \u5751 \u9664\u6cd5\u8981\u6c42 that division between two integers should truncate toward zero. \u6d4b\u8bd5\u6570\u636e\u91cc\u9762\u6709\u8d1f\u6570, python\u91cc\u9762\u6574\u6570\u9664\u6cd5\u7ed3\u679c\u5982\u679c\u662f\u5c0f\u6570\uff0c\u7ea6\u6210\u6574\u6570\u540e\u662f\u5f80\u5c0f\u7684\u65b9\u5411\u7ea6\u7684\u3002\u6bd4\u5982-0.4\u4f1a\u53d8\u6210-1\uff0c\u9898\u76ee\u8981\u6c42\u5f800\u7ea6\uff0c\u4e5f\u5c31\u662f-0.4\u53d8\u62100\u3002\u7528int(a\/b)\u53ef\u89e3\u51b3\u3002\u4e00\u4e2a\u51b7\u95e8\u77e5\u8bc6\u3002 Python\u89e3\u6cd5\" \/>\n<meta property=\"og:url\" content=\"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/\" \/>\n<meta property=\"og:site_name\" content=\"Feel Like Learning\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-07T01:11:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-06T16:29:30+00:00\" \/>\n<meta name=\"author\" content=\"feellikelearning\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"feellikelearning\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/\"},\"author\":{\"name\":\"feellikelearning\",\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"headline\":\"\u7b97\u6cd5\u7ec3\u4e60 \u529b\u6263 150. Evaluate Reverse Polish Notation\",\"datePublished\":\"2021-09-07T01:11:16+00:00\",\"dateModified\":\"2022-07-06T16:29:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/\"},\"wordCount\":30,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"articleSection\":[\"leetcode\",\"\u7b97\u6cd5\",\"\u7f16\u7a0b\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/\",\"url\":\"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/\",\"name\":\"\u7b97\u6cd5\u7ec3\u4e60 \u529b\u6263 150. Evaluate Reverse Polish Notation | Feel Like Learning\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/#website\"},\"datePublished\":\"2021-09-07T01:11:16+00:00\",\"dateModified\":\"2022-07-06T16:29:30+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/feellikelearning.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7b97\u6cd5\u7ec3\u4e60 \u529b\u6263 150. Evaluate Reverse Polish Notation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/feellikelearning.com\/#website\",\"url\":\"https:\/\/feellikelearning.com\/\",\"name\":\"Feel Like Learning\",\"description\":\"\u7a0b\u5e8f\uff5c\u751f\u6d3b\uff5c\u5b66\u5230\u5c31\u662f\u8d5a\u5230\",\"publisher\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/feellikelearning.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\",\"name\":\"feellikelearning\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g\",\"caption\":\"feellikelearning\"},\"logo\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/feellikelearning.com\/index.php\/author\/feellikelearning\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7b97\u6cd5\u7ec3\u4e60 \u529b\u6263 150. Evaluate Reverse Polish Notation | Feel Like Learning","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/","og_locale":"en_US","og_type":"article","og_title":"\u7b97\u6cd5\u7ec3\u4e60 \u529b\u6263 150. Evaluate Reverse Polish Notation | Feel Like Learning","og_description":"\u95ee\u9898\u603b\u7ed3 \u8fd9\u9898\u6bd4\u8f83\u7b80\u5355\uff0c\u5982\u679c\u5b66\u8fc7computer architecture\uff0c\u8fd9\u4e2aReverse Polish Notation (RPN)\u57fa\u672c\u5c31\u662f\u4e2astack machine\u3002\u5f88\u50cf\u6c47\u7f16\u8bed\u8a00\u3002\u7528stack\u5c31\u53ef\u4ee5\u89e3\u51b3\u3002 \u5751 \u9664\u6cd5\u8981\u6c42 that division between two integers should truncate toward zero. \u6d4b\u8bd5\u6570\u636e\u91cc\u9762\u6709\u8d1f\u6570, python\u91cc\u9762\u6574\u6570\u9664\u6cd5\u7ed3\u679c\u5982\u679c\u662f\u5c0f\u6570\uff0c\u7ea6\u6210\u6574\u6570\u540e\u662f\u5f80\u5c0f\u7684\u65b9\u5411\u7ea6\u7684\u3002\u6bd4\u5982-0.4\u4f1a\u53d8\u6210-1\uff0c\u9898\u76ee\u8981\u6c42\u5f800\u7ea6\uff0c\u4e5f\u5c31\u662f-0.4\u53d8\u62100\u3002\u7528int(a\/b)\u53ef\u89e3\u51b3\u3002\u4e00\u4e2a\u51b7\u95e8\u77e5\u8bc6\u3002 Python\u89e3\u6cd5","og_url":"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/","og_site_name":"Feel Like Learning","article_published_time":"2021-09-07T01:11:16+00:00","article_modified_time":"2022-07-06T16:29:30+00:00","author":"feellikelearning","twitter_card":"summary_large_image","twitter_misc":{"Written by":"feellikelearning","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/#article","isPartOf":{"@id":"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/"},"author":{"name":"feellikelearning","@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"headline":"\u7b97\u6cd5\u7ec3\u4e60 \u529b\u6263 150. Evaluate Reverse Polish Notation","datePublished":"2021-09-07T01:11:16+00:00","dateModified":"2022-07-06T16:29:30+00:00","mainEntityOfPage":{"@id":"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/"},"wordCount":30,"commentCount":0,"publisher":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"articleSection":["leetcode","\u7b97\u6cd5","\u7f16\u7a0b"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/","url":"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/","name":"\u7b97\u6cd5\u7ec3\u4e60 \u529b\u6263 150. Evaluate Reverse Polish Notation | Feel Like Learning","isPartOf":{"@id":"https:\/\/feellikelearning.com\/#website"},"datePublished":"2021-09-07T01:11:16+00:00","dateModified":"2022-07-06T16:29:30+00:00","breadcrumb":{"@id":"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/feellikelearning.com\/index.php\/2021\/09\/07\/leetcode-150-evaluate-reverse-polish-notation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/feellikelearning.com\/"},{"@type":"ListItem","position":2,"name":"\u7b97\u6cd5\u7ec3\u4e60 \u529b\u6263 150. Evaluate Reverse Polish Notation"}]},{"@type":"WebSite","@id":"https:\/\/feellikelearning.com\/#website","url":"https:\/\/feellikelearning.com\/","name":"Feel Like Learning","description":"\u7a0b\u5e8f\uff5c\u751f\u6d3b\uff5c\u5b66\u5230\u5c31\u662f\u8d5a\u5230","publisher":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/feellikelearning.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a","name":"feellikelearning","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g","caption":"feellikelearning"},"logo":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/"},"url":"https:\/\/feellikelearning.com\/index.php\/author\/feellikelearning\/"}]}},"_links":{"self":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/1248"}],"collection":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/comments?post=1248"}],"version-history":[{"count":1,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/1248\/revisions"}],"predecessor-version":[{"id":1249,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/1248\/revisions\/1249"}],"wp:attachment":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/media?parent=1248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/categories?post=1248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/tags?post=1248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}