{"id":60469,"date":"2026-01-15T16:49:18","date_gmt":"2026-01-15T08:49:18","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/60469.html"},"modified":"2026-01-15T16:49:18","modified_gmt":"2026-01-15T08:49:18","slug":"%e4%ba%8c%e5%8f%89%e6%a0%91%e5%89%8d%e5%ba%8f%e9%81%8d%e5%8e%86%e9%80%92%e5%bd%92%e5%ae%9e%e7%8e%b0%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/60469.html","title":{"rendered":"\u4e8c\u53c9\u6811\u524d\u5e8f\u904d\u5386\u9012\u5f52\u5b9e\u73b0\u8be6\u89e3"},"content":{"rendered":"<h2>\u3010LeetCode \u4e8c\u53c9\u6811\u3011\u524d\u5e8f\u904d\u5386\u9012\u5f52\u5b9e\u73b0\u8be6\u89e3\uff08\u9644\u8c03\u7528\u6808\u5206\u6790\uff09<\/h2>\n<p>\u672c\u6587\u8be6\u7ec6\u89e3\u6790\u4e8c\u53c9\u6811\u524d\u5e8f\u904d\u5386\u7684\u9012\u5f52\u5b9e\u73b0\u903b\u8f91\uff0c\u5e76\u901a\u8fc7\u4e24\u4e2a\u5177\u4f53\u4f8b\u5b50\uff08\u7b80\u5355\u6811\u4e0e\u590d\u6742\u6811\uff09\u9010\u6b65\u6f14\u793a\u9012\u5f52\u8c03\u7528\u6808\u7684\u6267\u884c\u8fc7\u7a0b\uff0c\u5e2e\u52a9\u4f60\u5f7b\u5e95\u7406\u89e3\u9012\u5f52\u5728\u6811\u904d\u5386\u4e2d\u7684\u5de5\u4f5c\u539f\u7406\u3002<\/p>\n<hr>\n<h3>\ud83d\udccc \u4e00\u3001\u4ee3\u7801\u5b9e\u73b0\u4e0e\u6ce8\u91ca<\/h3>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Solution<\/span> <span class=\"token punctuation\">{<\/p>\n<p>   <\/span><br \/>\n<span class=\"token keyword\">public<\/span><span class=\"token operator\">:<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u9012\u5f52\u904d\u5386\u51fd\u6570<\/span><br \/>\n    <span class=\"token comment\">\/\/ cur: \u5f53\u524d\u904d\u5386\u7684\u8282\u70b9\u6307\u9488<\/span><br \/>\n    <span class=\"token comment\">\/\/ vec: \u5f15\u7528\u4f20\u9012\u7684\u7ed3\u679c\u6570\u7ec4\uff0c\u7528\u4e8e\u5b58\u50a8\u904d\u5386\u7ed3\u679c<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">traversal<\/span><span class=\"token punctuation\">(<\/span>TreeNode<span class=\"token operator\">*<\/span> cur<span class=\"token punctuation\">,<\/span> vector<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">int<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token operator\">&amp;<\/span> vec<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/p>\n<p>   <\/span><br \/>\n        <span class=\"token comment\">\/\/ \u9012\u5f52\u7ec8\u6b62\u6761\u4ef6\uff1a\u5f53\u524d\u8282\u70b9\u4e3a\u7a7a\uff08\u5230\u8fbe\u53f6\u5b50\u8282\u70b9\u7684\u5b50\u8282\u70b9\uff09<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>cur <span class=\"token operator\">==<\/span> <span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">return<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ \u524d\u5e8f\u904d\u5386\uff1a\u6839 \u2192 \u5de6 \u2192 \u53f3<\/span><br \/>\n        vec<span class=\"token punctuation\">.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3010LeetCode \u4e8c\u53c9\u6811\u3011\u524d\u5e8f\u904d\u5386\u9012\u5f52\u5b9e\u73b0\u8be6\u89e3\uff08\u9644\u8c03\u7528\u6808\u5206\u6790\uff09 \u672c\u6587\u8be6\u7ec6\u89e3\u6790\u4e8c\u53c9\u6811\u524d\u5e8f\u904d\u5386\u7684\u9012\u5f52\u5b9e\u73b0\u903b\u8f91\uff0c\u5e76\u901a\u8fc7\u4e24\u4e2a\u5177\u4f53\u4f8b\u5b50\uff08\u7b80\u5355\u6811\u4e0e\u590d\u6742\u6811\uff09\u9010\u6b65\u6f14\u793a\u9012\u5f52\u8c03\u7528\u6808\u7684\u6267\u884c\u8fc7\u7a0b\uff0c\u5e2e\u52a9\u4f60\u5f7b\u5e95\u7406\u89e3\u9012\u5f52\u5728\u6811\u904d\u5386\u4e2d\u7684\u5de5\u4f5c\u539f\u7406\u3002 \ud83d\udccc \u4e00\u3001\u4ee3\u7801\u5b9e\u73b0\u4e0e\u6ce8\u91ca<br \/>\nclass Solution {public:\/\/ \u9012\u5f52\u904d\u5386\u51fd\u6570\/\/ cur: \u5f53\u524d\u904d\u5386\u7684\u8282\u70b9\u6307\u9488\/\/ vec: \u5f15\u7528\u4f20\u9012\u7684\u7ed3\u679c\u6570\u7ec4\uff0c\u7528\u4e8e\u5b58\u50a8\u904d\u5386\u7ed3\u679cvoid traversal(TreeNode* cur, vector&amp; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,190,1813,427],"topic":[],"class_list":["post-60469","post","type-post","status-publish","format-standard","hentry","category-server","tag-c","tag-190","tag-1813","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4e8c\u53c9\u6811\u524d\u5e8f\u904d\u5386\u9012\u5f52\u5b9e\u73b0\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/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:\/\/www.wsisp.com\/helps\/60469.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4e8c\u53c9\u6811\u524d\u5e8f\u904d\u5386\u9012\u5f52\u5b9e\u73b0\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u3010LeetCode \u4e8c\u53c9\u6811\u3011\u524d\u5e8f\u904d\u5386\u9012\u5f52\u5b9e\u73b0\u8be6\u89e3\uff08\u9644\u8c03\u7528\u6808\u5206\u6790\uff09 \u672c\u6587\u8be6\u7ec6\u89e3\u6790\u4e8c\u53c9\u6811\u524d\u5e8f\u904d\u5386\u7684\u9012\u5f52\u5b9e\u73b0\u903b\u8f91\uff0c\u5e76\u901a\u8fc7\u4e24\u4e2a\u5177\u4f53\u4f8b\u5b50\uff08\u7b80\u5355\u6811\u4e0e\u590d\u6742\u6811\uff09\u9010\u6b65\u6f14\u793a\u9012\u5f52\u8c03\u7528\u6808\u7684\u6267\u884c\u8fc7\u7a0b\uff0c\u5e2e\u52a9\u4f60\u5f7b\u5e95\u7406\u89e3\u9012\u5f52\u5728\u6811\u904d\u5386\u4e2d\u7684\u5de5\u4f5c\u539f\u7406\u3002 \ud83d\udccc \u4e00\u3001\u4ee3\u7801\u5b9e\u73b0\u4e0e\u6ce8\u91ca class Solution {public:\/\/ \u9012\u5f52\u904d\u5386\u51fd\u6570\/\/ cur: \u5f53\u524d\u904d\u5386\u7684\u8282\u70b9\u6307\u9488\/\/ vec: \u5f15\u7528\u4f20\u9012\u7684\u7ed3\u679c\u6570\u7ec4\uff0c\u7528\u4e8e\u5b58\u50a8\u904d\u5386\u7ed3\u679cvoid traversal(TreeNode* cur, vector&amp;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/60469.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-15T08:49:18+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/60469.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/60469.html\",\"name\":\"\u4e8c\u53c9\u6811\u524d\u5e8f\u904d\u5386\u9012\u5f52\u5b9e\u73b0\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-15T08:49:18+00:00\",\"dateModified\":\"2026-01-15T08:49:18+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/60469.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/60469.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/60469.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4e8c\u53c9\u6811\u524d\u5e8f\u904d\u5386\u9012\u5f52\u5b9e\u73b0\u8be6\u89e3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4e8c\u53c9\u6811\u524d\u5e8f\u904d\u5386\u9012\u5f52\u5b9e\u73b0\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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:\/\/www.wsisp.com\/helps\/60469.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4e8c\u53c9\u6811\u524d\u5e8f\u904d\u5386\u9012\u5f52\u5b9e\u73b0\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u3010LeetCode \u4e8c\u53c9\u6811\u3011\u524d\u5e8f\u904d\u5386\u9012\u5f52\u5b9e\u73b0\u8be6\u89e3\uff08\u9644\u8c03\u7528\u6808\u5206\u6790\uff09 \u672c\u6587\u8be6\u7ec6\u89e3\u6790\u4e8c\u53c9\u6811\u524d\u5e8f\u904d\u5386\u7684\u9012\u5f52\u5b9e\u73b0\u903b\u8f91\uff0c\u5e76\u901a\u8fc7\u4e24\u4e2a\u5177\u4f53\u4f8b\u5b50\uff08\u7b80\u5355\u6811\u4e0e\u590d\u6742\u6811\uff09\u9010\u6b65\u6f14\u793a\u9012\u5f52\u8c03\u7528\u6808\u7684\u6267\u884c\u8fc7\u7a0b\uff0c\u5e2e\u52a9\u4f60\u5f7b\u5e95\u7406\u89e3\u9012\u5f52\u5728\u6811\u904d\u5386\u4e2d\u7684\u5de5\u4f5c\u539f\u7406\u3002 \ud83d\udccc \u4e00\u3001\u4ee3\u7801\u5b9e\u73b0\u4e0e\u6ce8\u91ca class Solution {public:\/\/ \u9012\u5f52\u904d\u5386\u51fd\u6570\/\/ cur: \u5f53\u524d\u904d\u5386\u7684\u8282\u70b9\u6307\u9488\/\/ vec: \u5f15\u7528\u4f20\u9012\u7684\u7ed3\u679c\u6570\u7ec4\uff0c\u7528\u4e8e\u5b58\u50a8\u904d\u5386\u7ed3\u679cvoid traversal(TreeNode* cur, vector&amp;","og_url":"https:\/\/www.wsisp.com\/helps\/60469.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-15T08:49:18+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/60469.html","url":"https:\/\/www.wsisp.com\/helps\/60469.html","name":"\u4e8c\u53c9\u6811\u524d\u5e8f\u904d\u5386\u9012\u5f52\u5b9e\u73b0\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-15T08:49:18+00:00","dateModified":"2026-01-15T08:49:18+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/60469.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/60469.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/60469.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4e8c\u53c9\u6811\u524d\u5e8f\u904d\u5386\u9012\u5f52\u5b9e\u73b0\u8be6\u89e3"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/60469","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=60469"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/60469\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=60469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=60469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=60469"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=60469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}