{"id":662,"date":"2020-06-20T01:20:39","date_gmt":"2020-06-19T17:20:39","guid":{"rendered":"http:\/\/www.guanhaobo.cn\/?p=662"},"modified":"2020-06-20T01:20:39","modified_gmt":"2020-06-19T17:20:39","slug":"jz3-%e4%bb%8e%e5%b0%be%e5%88%b0%e5%a4%b4%e6%89%93%e5%8d%b0%e9%93%be%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/www.guanhaobo.cn\/?p=662","title":{"rendered":"JZ3 \u2014 \u4ece\u5c3e\u5230\u5934\u6253\u5370\u94fe\u8868"},"content":{"rendered":"<h3>\u9898\u76ee\u63cf\u8ff0<\/h3>\n<p>\u8f93\u5165\u4e00\u4e2a\u94fe\u8868\uff0c\u6309\u94fe\u8868\u4ece\u5c3e\u5230\u5934\u7684\u987a\u5e8f\u8fd4\u56de\u4e00\u4e2aArrayList\u3002<\/p>\n<h3>\u9898\u76ee\u5206\u6790<\/h3>\n<p>\u8fd9\u91cc\u7684\u94fe\u8868\u6307\u7684\u662f\u4ece\u5934\u5230\u5c3e\u7684\u5355\u5411\u94fe\u8868\u3002<br \/>\n\u4f7f\u7528\u6808\u5148\u8fdb\u540e\u51fa\u7684\u7279\u6027\uff0c\u4ece\u5934\u5230\u5c3e\u904d\u5386\u94fe\u8868\uff0c\u4f9d\u6b21\u5c06\u503c<code>push<\/code>\u8fdb\u6808\u4e2d\u3002\u6700\u540e\u4f9d\u6b21<code>pop<\/code>\u5373\u53ef\u3002<br \/>\n\u5f53\u7136\uff0c\u4e5f\u53ef\u4ee5\u7528\u5176\u4ed6\u7684\u5bb9\u5668\u3002\u603b\u4f53\u601d\u60f3\u662f\u76f8\u540c\u7684\uff0c\u5373\u5148\u628a\u6570\u636e\u6682\u65f6\u5b58\u8d77\u6765\uff0c\u7136\u540e\u6309\u7167\u8981\u6c42\u7684\u987a\u5e8f\u8f93\u51fa\u3002<\/p>\n<h3>C++<\/h3>\n<pre><code class=\"language-cpp line-numbers\">\/**\n*  struct ListNode {\n*        int val;\n*        struct ListNode *next;\n*        ListNode(int x) :\n*              val(x), next(NULL) {\n*        }\n*  };\n*\/\nclass Solution\n{\npublic:\n    vector&lt;int&gt; printListFromTailToHead(ListNode *head)\n    {\n        stack&lt;int&gt; s;\n        vector&lt;int&gt; ans;\n        while (head != NULL)\n        {\n            s.push(head-&gt;val);\n            head = head-&gt;next;\n        }\n        while (!s.empty())\n        {\n            ans.push_back(s.top());\n            s.pop();\n        }\n        return ans;\n    }\n};\n<\/code><\/pre>\n<h3>Java<\/h3>\n<pre><code class=\"language-java line-numbers\">\/**\n*    public class ListNode {\n*        int val;\n*        ListNode next = null;\n*\n*        ListNode(int val) {\n*            this.val = val;\n*        }\n*    }\n*\n*\/\nimport java.util.*;\npublic class Solution {\n    public ArrayList&lt;Integer&gt; printListFromTailToHead(ListNode listNode) {\n        Stack&lt;Integer&gt; stack = new Stack();\n        while (listNode != null) {\n            stack.push(listNode.val);\n            listNode = listNode.next;\n        }\n        ArrayList&lt;Integer&gt; ans = new ArrayList&lt;Integer&gt;();\n        while (!stack.empty()) {\n            ans.add(stack.pop());\n        }\n        return ans;\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u63cf\u8ff0 \u8f93\u5165\u4e00\u4e2a\u94fe\u8868\uff0c\u6309\u94fe\u8868\u4ece\u5c3e\u5230\u5934\u7684\u987a\u5e8f\u8fd4\u56de\u4e00\u4e2aArrayList\u3002 \u9898\u76ee\u5206\u6790 \u8fd9\u91cc\u7684\u94fe\u8868\u6307\u7684\u662f\u4ece\u5934\u5230\u5c3e\u7684 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[39],"class_list":["post-662","post","type-post","status-publish","format-standard","hentry","category-algo","tag-offer"],"_links":{"self":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/662","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=662"}],"version-history":[{"count":0,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/662\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}