{"id":1402,"date":"2024-01-31T10:13:08","date_gmt":"2024-01-31T02:13:08","guid":{"rendered":"http:\/\/zyg.luchers.cn\/?p=1402"},"modified":"2024-01-31T10:13:08","modified_gmt":"2024-01-31T02:13:08","slug":"150%e3%80%81%e9%80%86%e6%b3%a2%e5%85%b0%e8%a1%a8%e8%be%be%e5%bc%8f%e6%b1%82%e5%80%bc%e3%80%90%e4%b8%ad%e7%ad%89%e3%80%91","status":"publish","type":"post","link":"http:\/\/zyg.luchers.cn\/index.php\/2024\/01\/31\/150%e3%80%81%e9%80%86%e6%b3%a2%e5%85%b0%e8%a1%a8%e8%be%be%e5%bc%8f%e6%b1%82%e5%80%bc%e3%80%90%e4%b8%ad%e7%ad%89%e3%80%91\/","title":{"rendered":"150\u3001\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u6c42\u503c\u3010\u4e2d\u7b49\u3011"},"content":{"rendered":"<h1>\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u6c42\u503c\u3010\u4e2d\u7b49\u3011<\/h1>\n<h2>\u9898\u76ee<\/h2>\n<p>\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 tokens \uff0c\u8868\u793a\u4e00\u4e2a\u6839\u636e \u9006\u6ce2\u5170\u8868\u793a\u6cd5 \u8868\u793a\u7684\u7b97\u672f\u8868\u8fbe\u5f0f\u3002<\/p>\n<p>\u8bf7\u4f60\u8ba1\u7b97\u8be5\u8868\u8fbe\u5f0f\u3002\u8fd4\u56de\u4e00\u4e2a\u8868\u793a\u8868\u8fbe\u5f0f\u503c\u7684\u6574\u6570\u3002<\/p>\n<p>\u6ce8\u610f\uff1a<\/p>\n<p>\u6709\u6548\u7684\u7b97\u7b26\u4e3a '+'\u3001'-'\u3001'*' \u548c '\/' \u3002<br \/>\n\u6bcf\u4e2a\u64cd\u4f5c\u6570\uff08\u8fd0\u7b97\u5bf9\u8c61\uff09\u90fd\u53ef\u4ee5\u662f\u4e00\u4e2a\u6574\u6570\u6216\u8005\u53e6\u4e00\u4e2a\u8868\u8fbe\u5f0f\u3002<br \/>\n\u4e24\u4e2a\u6574\u6570\u4e4b\u95f4\u7684\u9664\u6cd5\u603b\u662f \u5411\u96f6\u622a\u65ad \u3002<br \/>\n\u8868\u8fbe\u5f0f\u4e2d\u4e0d\u542b\u9664\u96f6\u8fd0\u7b97\u3002<br \/>\n\u8f93\u5165\u662f\u4e00\u4e2a\u6839\u636e\u9006\u6ce2\u5170\u8868\u793a\u6cd5\u8868\u793a\u7684\u7b97\u672f\u8868\u8fbe\u5f0f\u3002<br \/>\n\u7b54\u6848\u53ca\u6240\u6709\u4e2d\u95f4\u8ba1\u7b97\u7ed3\u679c\u53ef\u4ee5\u7528 32 \u4f4d \u6574\u6570\u8868\u793a\u3002<\/p>\n<p>\u793a\u4f8b 1\uff1a<\/p>\n<p>\u8f93\u5165\uff1atokens = [&quot;2&quot;,&quot;1&quot;,&quot;+&quot;,&quot;3&quot;,&quot;<em>&quot;]<br \/>\n\u8f93\u51fa\uff1a9<br \/>\n\u89e3\u91ca\uff1a\u8be5\u7b97\u5f0f\u8f6c\u5316\u4e3a\u5e38\u89c1\u7684\u4e2d\u7f00\u7b97\u672f\u8868\u8fbe\u5f0f\u4e3a\uff1a((2 + 1) <\/em> 3) = 9<br \/>\n\u793a\u4f8b 2\uff1a<\/p>\n<p>\u8f93\u5165\uff1atokens = [&quot;4&quot;,&quot;13&quot;,&quot;5&quot;,&quot;\/&quot;,&quot;+&quot;]<br \/>\n\u8f93\u51fa\uff1a6<br \/>\n\u89e3\u91ca\uff1a\u8be5\u7b97\u5f0f\u8f6c\u5316\u4e3a\u5e38\u89c1\u7684\u4e2d\u7f00\u7b97\u672f\u8868\u8fbe\u5f0f\u4e3a\uff1a(4 + (13 \/ 5)) = 6<br \/>\n\u793a\u4f8b 3\uff1a<\/p>\n<p>\u8f93\u5165\uff1atokens = [&quot;10&quot;,&quot;6&quot;,&quot;9&quot;,&quot;3&quot;,&quot;+&quot;,&quot;-11&quot;,&quot;<em>&quot;,&quot;\/&quot;,&quot;<\/em>&quot;,&quot;17&quot;,&quot;+&quot;,&quot;5&quot;,&quot;+&quot;]<br \/>\n\u8f93\u51fa\uff1a22<br \/>\n\u89e3\u91ca\uff1a\u8be5\u7b97\u5f0f\u8f6c\u5316\u4e3a\u5e38\u89c1\u7684\u4e2d\u7f00\u7b97\u672f\u8868\u8fbe\u5f0f\u4e3a\uff1a<br \/>\n((10 <em> (6 \/ ((9 + 3) <\/em> -11))) + 17) + 5<br \/>\n= ((10 <em> (6 \/ (12 <\/em> -11))) + 17) + 5<br \/>\n= ((10 <em> (6 \/ -132)) + 17) + 5<br \/>\n= ((10 <\/em> 0) + 17) + 5<br \/>\n= (0 + 17) + 5<br \/>\n= 17 + 5<br \/>\n= 22<\/p>\n<h2>\u601d\u8def<\/h2>\n<h3>\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u7684\u64cd\u4f5c\u6b65\u9aa4<\/h3>\n<p>1\u3001\u4ece\u5de6\u5230\u53f3\u904d\u5386\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\uff0c\u8fdb\u884c\u5982\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<p>2\u3001\u5982\u679c\u9047\u5230\u64cd\u4f5c\u6570\uff0c\u5219\u5c06\u64cd\u4f5c\u6570\u5165\u6808\uff1b<\/p>\n<p>3\u3001\u5982\u679c\u9047\u5230\u8fd0\u7b97\u7b26\uff0c\u5219\u5c06\u4e24\u4e2a\u64cd\u4f5c\u6570\u51fa\u6808\uff0c\u5176\u4e2d\u5148\u51fa\u6808\u7684\u662f\u53f3\u64cd\u4f5c\u6570\uff0c\u540e\u51fa\u6808\u7684\u662f\u5de6\u64cd\u4f5c\u6570\uff0c\u4f7f\u7528\u8fd0\u7b97\u7b26\u5bf9\u4e24\u4e2a\u64cd\u4f5c\u6570\u8fdb\u884c\u8fd0\u7b97\uff0c\u5c06\u8fd0\u7b97\u5f97\u5230\u7684\u65b0\u64cd\u4f5c\u6570\u5165\u6808\u3002<\/p>\n<p>4\u3001\u6574\u4e2a\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u904d\u5386\u5b8c\u6bd5\u4e4b\u540e\uff0c\u6808\u5185\u53ea\u6709\u4e00\u4e2a\u5143\u7d20\uff0c\u8be5\u5143\u7d20\u5373\u4e3a\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u7684\u503c\u3002<\/p>\n<p>5\u3001\u6211\u4eec\u8fd9\u91cc\u7b80\u5355\u8bf4\u5c31\u662f\u628a\u6bcf\u4e2a\u503c\u53d6\u51fa\uff0c\u5982\u679c\u662f\u9047\u5230\u8fd0\u7b97\u7b26\uff0c\u5c31\u53d6\u4e24\u4e2a\u6570\u5b57\u51fa\u6765\uff0c\u7136\u540e\u518d\u628a\u8fd9\u4e2a\u7ed3\u679c\u653e\u5165\u5230\u6808\u4e2d\u3002\u4ee5\u6b64\u7c7b\u63a8<\/p>\n<p>6\u3001\u5982\u679c\u4e0d\u662f\u8fd0\u7b97\u7b26\u5c31\u662f\u6570\u5b57\uff0c\u6211\u4eec\u628a\u6570\u5b57\u653e\u5165\u5230\u6808\u4e2d\u5c31\u884c\u3002\u7ecf\u8fc7\u4e00\u7cfb\u5217\u5faa\u73af\u5c31\u53ef\u4ee5\u77e5\u9053\uff0c\u6808\u4e2d\u6700\u540e\u5269\u4e0b\u90a3\u4e2a\u5c31\u662f\u7ed3\u679c<\/p>\n<h2>\u4ee3\u7801\u5b9e\u73b0\u3010java\u3011<\/h2>\n<pre><code class=\"language-java\">class Solution {\n    public int evalRPN(String[] tokens) {\n        Stack&lt;Integer&gt; stack = new Stack();\n        for(String s:tokens){\n            if(&quot;+&quot;.equals(s)){\n                \/\/ \u8fd9\u91cc\u591a\u4e86\u4e2a\u6b63\u8d1f\u53f7\u7684\u539f\u56e0\u662f\u4e3a\u4e86\u907f\u514d+-\u9519\u8bef\n                stack.push(-stack.pop()+stack.pop());\n            }else if(&quot;-&quot;.equals(s)){\n                stack.push(-stack.pop()+stack.pop());\n            }else if(&quot;*&quot;.equals(s)){\n                stack.push(stack.pop()*stack.pop());\n            }else if(&quot;\/&quot;.equals(s)){\n                \/\/ \u8fd9\u8fb9\u9664\u6cd5\u9700\u8981\u6ce8\u610f\u4e00\u4e0b\uff0c\u8bbe\u7f6e\u4e24\u4e2a\u53d8\u91cf\uff0c\u5426\u5219\u5bb9\u6613\u62a5\u9519\/zero\n                int num1 = stack.pop();\n                int num2 = stack.pop();\n                stack.push(num1\/num2);\n            }else{\n                \/\/ \u5982\u679c\u90fd\u4e0d\u6ee1\u8db3\uff0c\u6211\u4eec\u5c31\u628a\u5b57\u7b26\u4e32\u6570\u5b57\uff0c\u8f6c\u6362\u6210int\u7c7b\u578b\u7684\u6570\u5b57\u5b58\u5165\u5230\u6808\u4e2d\n                stack.push(Integer.valueOf(s));\n            }\n        }\n        \/\/ \u6700\u540e\u628a\u7ed3\u679c\u8fd4\u56de\u5c31\u884c,\u6b64\u65f6\u6808\u4e2d\u5c31\u53ea\u6709\u4e00\u4e2a\u6570\u5b57\uff0c\u5c31\u662f\u7b54\u6848\n        return stack.pop();\n    }\n}<\/code><\/pre>\n<p>\u4f5c\u8005\uff1a\u529b\u6263\u5b98\u65b9\u9898\u89e3<br \/>\n\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/evaluate-reverse-polish-notation\/solutions\/667892\/ni-bo-lan-biao-da-shi-qiu-zhi-by-leetcod-wue9\/\">https:\/\/leetcode.cn\/problems\/evaluate-reverse-polish-notation\/solutions\/667892\/ni-bo-lan-biao-da-shi-qiu-zhi-by-leetcod-wue9\/<\/a><br \/>\n\u6765\u6e90\uff1a\u529b\u6263\uff08LeetCode\uff09<br \/>\n\u8457\u4f5c\u6743\u5f52\u4f5c\u8005\u6240\u6709\u3002\u5546\u4e1a\u8f6c\u8f7d\u8bf7\u8054\u7cfb\u4f5c\u8005\u83b7\u5f97\u6388\u6743\uff0c\u975e\u5546\u4e1a\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9006\u6ce2\u5170\u8868\u8fbe\u5f0f\u6c42\u503c\u3010\u4e2d\u7b49\u3011 \u9898\u76ee \u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 tokens \uff0c\u8868\u793a\u4e00\u4e2a\u6839\u636e \u9006\u6ce2\u5170\u8868\u793a\u6cd5 \u8868\u793a\u7684\u7b97\u672f\u8868\u8fbe [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1402","post","type-post","status-publish","format-standard","hentry","category-stack"],"_links":{"self":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts\/1402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1402"}],"version-history":[{"count":0,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts\/1402\/revisions"}],"wp:attachment":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1402"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}