{"id":108484,"date":"2026-09-21T21:08:35","date_gmt":"2026-09-21T13:08:35","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/108484.html"},"modified":"2026-09-21T21:08:35","modified_gmt":"2026-09-21T13:08:35","slug":"%e3%80%90classic-150-%e5%88%b7%e9%a2%98%e8%ae%a1%e5%88%92%e3%80%91-leetcode-130-%e8%a2%ab%e5%9b%b4%e7%bb%95%e7%9a%84%e5%8c%ba%e5%9f%9f-c-%e7%9f%a9%e9%98%b5-dfs-%e4%b8%8e%e9%80%86%e5%90%91","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/108484.html","title":{"rendered":"\u3010Classic 150 \u5237\u9898\u8ba1\u5212\u3011 LeetCode 130. \u88ab\u56f4\u7ed5\u7684\u533a\u57df | C++ \u77e9\u9635 DFS \u4e0e\u9006\u5411\u8fb9\u754c\u4fdd\u62a4\u6cd5"},"content":{"rendered":"<h2>LeetCode 130. \u88ab\u56f4\u7ed5\u7684\u533a\u57df<\/h2>\n<h3>&#x1f4cc; \u9898\u76ee\u63cf\u8ff0<\/h3>\n<p>\u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u77e9\u9635 board &#xff0c;\u7531\u82e5\u5e72\u5b57\u7b26 &#039;X&#039; \u548c &#039;O&#039; \u7ec4\u6210&#xff0c;\u6355\u83b7 \u6240\u6709 \u88ab\u56f4\u7ed5\u7684\u533a\u57df&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8fde\u63a5&#xff1a;\u4e00\u4e2a\u5355\u5143\u683c\u4e0e\u6c34\u5e73\u6216\u5782\u76f4\u65b9\u5411\u4e0a\u76f8\u90bb\u7684\u5355\u5143\u683c\u8fde\u63a5\u3002<\/p>\n<\/li>\n<li>\n<p>\u533a\u57df&#xff1a;\u8fde\u63a5\u6240\u6709 &#039;O&#039; \u7684\u5355\u5143\u683c\u6765\u5f62\u6210\u4e00\u4e2a\u533a\u57df\u3002<\/p>\n<\/li>\n<li>\n<p>\u56f4\u7ed5&#xff1a;\u5982\u679c\u4e00\u4e2a\u533a\u57df\u4e2d\u7684\u6240\u6709 &#039;O&#039; \u5355\u5143\u683c\u90fd\u4e0d\u5728\u68cb\u76d8\u7684\u8fb9\u7f18&#xff0c;\u5219\u8be5\u533a\u57df\u88ab\u5305\u56f4\u3002\u8fd9\u6837\u7684\u533a\u57df\u5b8c\u5168\u88ab &#039;X&#039; \u5355\u5143\u683c\u5305\u56f4\u3002<br \/>\n\u901a\u8fc7 \u539f\u5730 \u5c06\u8f93\u5165\u77e9\u9635\u4e2d\u7684\u6240\u6709 &#039;O&#039; \u66ff\u6362\u4e3a &#039;X&#039; \u6765\u6355\u83b7\u88ab\u56f4\u7ed5\u7684\u533a\u57df\u3002<\/p>\n<\/li>\n<li>\n<p>\u793a\u4f8b 1:<br \/>\n\u8f93\u5165&#xff1a;board &#061; [[&#034;X&#034;,&#034;X&#034;,&#034;X&#034;,&#034;X&#034;],[&#034;X&#034;,&#034;O&#034;,&#034;O&#034;,&#034;X&#034;],[&#034;X&#034;,&#034;X&#034;,&#034;O&#034;,&#034;X&#034;],[&#034;X&#034;,&#034;O&#034;,&#034;X&#034;,&#034;X&#034;]]<br \/>\n\u8f93\u51fa&#xff1a;[[&#034;X&#034;,&#034;X&#034;,&#034;X&#034;,&#034;X&#034;],[&#034;X&#034;,&#034;X&#034;,&#034;X&#034;,&#034;X&#034;],[&#034;X&#034;,&#034;X&#034;,&#034;X&#034;,&#034;X&#034;],[&#034;X&#034;,&#034;O&#034;,&#034;X&#034;,&#034;X&#034;]]<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>&#x1f4a1; \u7834\u9898\u601d\u8def&#xff1a;\u9006\u5411\u601d\u7ef4 (\u4ece\u8fb9\u7f18\u51fa\u53d1\u7684 DFS \u6807\u8bb0)<\/h3>\n<p>\u5982\u679c\u6b63\u5411\u53bb\u68c0\u67e5\u6bcf\u4e00\u4e2a\u5185\u90e8\u7684 &#039;O&#039; \u662f\u4e0d\u662f\u88ab\u5305\u56f4&#xff0c;\u9700\u8981\u5904\u7406\u5927\u91cf\u7684\u8fde\u901a\u6027\u8fb9\u754c&#xff0c;\u6781\u5176\u590d\u6742\u3002<br \/>\n\u5927\u5382\u6ee1\u5206\u79d8\u7c4d&#xff1a;\u9006\u5411\u601d\u7ef4&#xff08;\u4fdd\u536b\u8fb9\u533a&#xff09;<br \/>\n\u6240\u6709\u80fd\u591f\u76f4\u63a5\u6216\u95f4\u63a5\u548c\u77e9\u9635\u8fb9\u7f18\u7684 &#039;O&#039; \u8fde\u901a\u7684 &#039;O&#039;&#xff0c;\u90fd\u662f\u7edd\u5bf9\u4e0d\u53ef\u80fd\u88ab\u5305\u56f4\u7684\u201c\u6f0f\u7f51\u4e4b\u9c7c\u201d\u3002<\/p>\n<p>\u7b97\u6cd5\u6b65\u9aa4&#xff1a;<\/p>\n<li>\u641c\u5bfb\u8fb9\u7f18&#xff1a;\u904d\u5386\u77e9\u9635\u7684\u56db\u6761\u8fb9\u754c&#xff08;\u7b2c\u4e00\u884c\u3001\u6700\u540e\u4e00\u884c\u3001\u7b2c\u4e00\u5217\u3001\u6700\u540e\u4e00\u5217&#xff09;\u3002<\/li>\n<li>\u6df1\u5ea6\u4f18\u5148\u641c\u7d22 (DFS)&#xff1a;\u4e00\u65e6\u5728\u8fb9\u754c\u4e0a\u53d1\u73b0\u4e86 &#039;O&#039;&#xff0c;\u7acb\u523b\u4ee5\u5b83\u4e3a\u8d77\u70b9\u5f00\u59cb DFS&#xff0c;\u628a\u6240\u6709\u548c\u5b83\u8fde\u901a\u7684 &#039;O&#039; \u5168\u90e8\u6253\u4e0a\u8bbf\u95ee\u6807\u8bb0&#xff08;\u6216\u8005\u539f\u5730\u4fee\u6539\u4e3a\u4e00\u4e2a\u7279\u6b8a\u5b57\u7b26&#xff0c;\u5982 &#039;A&#039;&#xff09;\u3002<\/li>\n<li>\u5168\u5c40\u6e05\u6d17&#xff1a;\u518d\u6b21\u904d\u5386\u6574\u4e2a\u77e9\u9635&#xff1a;\n<ul>\n<li>\u88ab\u6807\u8bb0\u8fc7&#xff08;\u6216\u4fee\u6539\u8fc7&#xff09;\u7684 &#039;O&#039;&#xff1a;\u8bf4\u660e\u5b83\u4eec\u4e0e\u8fb9\u7f18\u76f8\u8fde&#xff0c;\u5c5e\u4e8e\u5b89\u5168\u533a&#xff0c;\u6062\u590d\u6216\u4fdd\u6301\u4e3a &#039;O&#039;\u3002<\/li>\n<li>\u6ca1\u88ab\u6807\u8bb0\u8fc7\u7684 &#039;O&#039;&#xff1a;\u8bf4\u660e\u5b83\u4eec\u88ab\u5bc6\u4e0d\u900f\u98ce\u7684 &#039;X&#039; \u5f7b\u5e95\u5305\u56f4&#xff0c;\u65e0\u8def\u53ef\u9003&#xff0c;\u5168\u90e8\u65e0\u60c5\u8f6c\u5316\u4e3a &#039;X&#039;\u3002<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h3>&#x1f4bb; C&#043;&#043; \u4ee3\u7801\u5b9e\u73b0 (\u539f\u6c41\u539f\u5473\u4f5c\u8005\u7248)<\/h3>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Solution<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">public<\/span><span class=\"token operator\">:<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u65b9\u5411\u5411\u91cf&#xff1a;\u53f3\u3001\u4e0b\u3001\u5de6\u3001\u4e0a<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> dx<span class=\"token punctuation\">[<\/span><span class=\"token number\">4<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> dy<span class=\"token punctuation\">[<\/span><span class=\"token number\">4<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u26a0\ufe0f \u6ce8\u610f&#xff1a;\u56fa\u5b9a\u5927\u5c0f\u7684 st \u6570\u7ec4\u5728\u77e9\u9635\u8d85\u8fc7 210&#215;210 \u65f6\u4f1a\u8d8a\u754c<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5de5\u4e1a\u7ea7\u5efa\u8bae\u76f4\u63a5\u5728\u539f\u5730\u4fee\u6539 board \u5b57\u7b26&#xff08;\u5982\u6539\u6210 &#039;A&#039;&#xff09;\u6765\u7701\u53bb st \u6570\u7ec4<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> st<span class=\"token punctuation\">[<\/span><span class=\"token number\">210<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">210<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> m<span class=\"token punctuation\">,<\/span> n<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">void<\/span> <span class=\"token function\">solve<\/span><span class=\"token punctuation\">(<\/span>vector<span class=\"token operator\">&lt;<\/span>vector<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">char<\/span><span class=\"token operator\">&gt;&gt;<\/span><span class=\"token operator\">&amp;<\/span> board<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        m <span class=\"token operator\">&#061;<\/span> board<span class=\"token punctuation\">.<\/span><span class=\"token function\">size<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> n <span class=\"token operator\">&#061;<\/span> board<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">size<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ 1. \u626b\u63cf\u56db\u6761\u8fb9\u754c&#xff0c;\u5bfb\u627e\u6240\u6709\u4e0e\u8fb9\u7f18\u76f8\u8fde\u7684 &#039;O&#039;<\/span><br \/>\n        <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> m<span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&#043;&#043;<\/span> <span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> j <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> j <span class=\"token operator\">&lt;<\/span> n<span class=\"token punctuation\">;<\/span> j <span class=\"token operator\">&#043;&#043;<\/span> <span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token punctuation\">{<\/span><br \/>\n                <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>board<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token char\">&#039;O&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n                <span class=\"token punctuation\">{<\/span><br \/>\n                    <span class=\"token comment\">\/\/ \u5982\u679c\u5f53\u524d\u70b9\u843d\u5728\u56db\u6761\u8fb9\u754c\u4e0a&#xff0c;\u7acb\u523b\u89e6\u53d1 DFS \u8fde\u901a\u5757\u6807\u8bb0<\/span><br \/>\n                    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>i <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span> <span class=\"token operator\">||<\/span> j <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span> <span class=\"token operator\">||<\/span> i <span class=\"token operator\">&#061;&#061;<\/span> m <span class=\"token operator\">&#8211;<\/span> <span class=\"token number\">1<\/span> <span class=\"token operator\">||<\/span> j <span class=\"token operator\">&#061;&#061;<\/span> n <span class=\"token operator\">&#8211;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><br \/>\n                        <span class=\"token function\">dfs<\/span><span class=\"token punctuation\">(<\/span>i<span class=\"token punctuation\">,<\/span> j<span class=\"token punctuation\">,<\/span> board<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n                <span class=\"token punctuation\">}<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ 2. \u5168\u5c40\u6e05\u527f&#xff1a;\u6839\u636e st \u72b6\u6001\u91cd\u5851\u77e9\u9635<\/span><br \/>\n        <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> m<span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&#043;&#043;<\/span> <span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> j <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> j <span class=\"token operator\">&lt;<\/span> n<span class=\"token punctuation\">;<\/span> j <span class=\"token operator\">&#043;&#043;<\/span> <span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token punctuation\">{<\/span><br \/>\n                <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>st<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> board<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token char\">&#039;O&#039;<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u8fb9\u7f18\u8fde\u901a\u7684\u5b89\u5168\u533a&#xff0c;\u4fdd\u7559<\/span><br \/>\n                <span class=\"token keyword\">else<\/span> board<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token char\">&#039;X&#039;<\/span><span class=\"token punctuation\">;<\/span>         <span class=\"token comment\">\/\/ \u5185\u90e8\u88ab\u5305\u56f4\u7684\u6b7b\u533a&#xff0c;\u5168\u90e8\u6740\u6b7b<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">void<\/span> <span class=\"token function\">dfs<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> x<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> y<span class=\"token punctuation\">,<\/span> vector<span class=\"token operator\">&lt;<\/span>vector<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">char<\/span><span class=\"token operator\">&gt;&gt;<\/span><span class=\"token operator\">&amp;<\/span> board<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        st<span class=\"token punctuation\">[<\/span>x<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>y<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u6807\u8bb0\u4e3a\u5b89\u5168\u72b6\u6001<\/span><\/p>\n<p>        <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">4<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&#043;&#043;<\/span> <span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">int<\/span> xx <span class=\"token operator\">&#061;<\/span> x <span class=\"token operator\">&#043;<\/span> dx<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> yy <span class=\"token operator\">&#061;<\/span> y <span class=\"token operator\">&#043;<\/span> dy<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u8d8a\u754c\u68c0\u67e5 &#043; \u5fc5\u987b\u662f &#039;O&#039; &#043; \u5fc5\u987b\u672a\u88ab\u8bbf\u95ee\u8fc7<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>xx <span class=\"token operator\">&gt;&#061;<\/span> <span class=\"token number\">0<\/span> <span class=\"token operator\">&amp;&amp;<\/span> xx <span class=\"token operator\">&lt;<\/span> m <span class=\"token operator\">&amp;&amp;<\/span> yy <span class=\"token operator\">&gt;&#061;<\/span> <span class=\"token number\">0<\/span> <span class=\"token operator\">&amp;&amp;<\/span> yy <span class=\"token operator\">&lt;<\/span> n <span class=\"token operator\">&amp;&amp;<\/span> board<span class=\"token punctuation\">[<\/span>xx<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>yy<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token char\">&#039;O&#039;<\/span> <span class=\"token operator\">&amp;&amp;<\/span> <span class=\"token operator\">!<\/span>st<span class=\"token punctuation\">[<\/span>xx<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span>yy<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token punctuation\">{<\/span><br \/>\n                <span class=\"token function\">dfs<\/span><span class=\"token punctuation\">(<\/span>xx<span class=\"token punctuation\">,<\/span> yy<span class=\"token punctuation\">,<\/span> board<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>LeetCode 130. \u88ab\u56f4\u7ed5\u7684\u533a\u57df<br \/>\n&#x1f4cc; \u9898\u76ee\u63cf\u8ff0<br \/>\n\u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u77e9\u9635 board &#xff0c;\u7531\u82e5\u5e72\u5b57\u7b26 X \u548c O \u7ec4\u6210&#xff0c;\u6355\u83b7 \u6240\u6709 \u88ab\u56f4\u7ed5\u7684\u533a\u57df&#xff1a;\u8fde\u63a5&#xff1a;\u4e00\u4e2a\u5355\u5143\u683c\u4e0e\u6c34\u5e73\u6216\u5782\u76f4\u65b9\u5411\u4e0a\u76f8\u90bb\u7684\u5355\u5143\u683c\u8fde\u63a5\u3002\u533a\u57df&#xff1a;\u8fde\u63a5\u6240\u6709 O \u7684\u5355\u5143\u683c\u6765\u5f62\u6210\u4e00\u4e2a\u533a\u57df\u3002\u56f4\u7ed5&#xff1a;\u5982\u679c\u4e00\u4e2a\u533a\u57df\u4e2d\u7684\u6240\u6709 O \u5355\u5143\u683c\u90fd\u4e0d\u5728\u68cb\u76d8\u7684\u8fb9\u7f18&#xff0c;\u5219\u8be5\u533a\u57df\u88ab\u5305\u56f4\u3002\u8fd9\u6837\u7684\u533a\u57df\u5b8c\u5168\u88ab X \u5355\u5143\u683c\u5305\u56f4\u3002<br \/>\n\u901a\u8fc7 <\/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":[11653,55,2692,427],"topic":[],"class_list":["post-108484","post","type-post","status-publish","format-standard","hentry","category-server","tag-11653","tag-c","tag-leetcode","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Classic 150 \u5237\u9898\u8ba1\u5212\u3011 LeetCode 130. \u88ab\u56f4\u7ed5\u7684\u533a\u57df | C++ \u77e9\u9635 DFS \u4e0e\u9006\u5411\u8fb9\u754c\u4fdd\u62a4\u6cd5 - \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\/108484.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Classic 150 \u5237\u9898\u8ba1\u5212\u3011 LeetCode 130. \u88ab\u56f4\u7ed5\u7684\u533a\u57df | C++ \u77e9\u9635 DFS \u4e0e\u9006\u5411\u8fb9\u754c\u4fdd\u62a4\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"LeetCode 130. \u88ab\u56f4\u7ed5\u7684\u533a\u57df &#x1f4cc; \u9898\u76ee\u63cf\u8ff0 \u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u77e9\u9635 board &#xff0c;\u7531\u82e5\u5e72\u5b57\u7b26 X \u548c O \u7ec4\u6210&#xff0c;\u6355\u83b7 \u6240\u6709 \u88ab\u56f4\u7ed5\u7684\u533a\u57df&#xff1a;\u8fde\u63a5&#xff1a;\u4e00\u4e2a\u5355\u5143\u683c\u4e0e\u6c34\u5e73\u6216\u5782\u76f4\u65b9\u5411\u4e0a\u76f8\u90bb\u7684\u5355\u5143\u683c\u8fde\u63a5\u3002\u533a\u57df&#xff1a;\u8fde\u63a5\u6240\u6709 O \u7684\u5355\u5143\u683c\u6765\u5f62\u6210\u4e00\u4e2a\u533a\u57df\u3002\u56f4\u7ed5&#xff1a;\u5982\u679c\u4e00\u4e2a\u533a\u57df\u4e2d\u7684\u6240\u6709 O \u5355\u5143\u683c\u90fd\u4e0d\u5728\u68cb\u76d8\u7684\u8fb9\u7f18&#xff0c;\u5219\u8be5\u533a\u57df\u88ab\u5305\u56f4\u3002\u8fd9\u6837\u7684\u533a\u57df\u5b8c\u5168\u88ab X \u5355\u5143\u683c\u5305\u56f4\u3002 \u901a\u8fc7\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/108484.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-21T13:08:35+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\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/108484.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/108484.html\",\"name\":\"\u3010Classic 150 \u5237\u9898\u8ba1\u5212\u3011 LeetCode 130. \u88ab\u56f4\u7ed5\u7684\u533a\u57df | C++ \u77e9\u9635 DFS \u4e0e\u9006\u5411\u8fb9\u754c\u4fdd\u62a4\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-21T13:08:35+00:00\",\"dateModified\":\"2026-09-21T13:08:35+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/108484.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/108484.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/108484.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Classic 150 \u5237\u9898\u8ba1\u5212\u3011 LeetCode 130. \u88ab\u56f4\u7ed5\u7684\u533a\u57df | C++ \u77e9\u9635 DFS \u4e0e\u9006\u5411\u8fb9\u754c\u4fdd\u62a4\u6cd5\"}]},{\"@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":"\u3010Classic 150 \u5237\u9898\u8ba1\u5212\u3011 LeetCode 130. \u88ab\u56f4\u7ed5\u7684\u533a\u57df | C++ \u77e9\u9635 DFS \u4e0e\u9006\u5411\u8fb9\u754c\u4fdd\u62a4\u6cd5 - \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\/108484.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Classic 150 \u5237\u9898\u8ba1\u5212\u3011 LeetCode 130. \u88ab\u56f4\u7ed5\u7684\u533a\u57df | C++ \u77e9\u9635 DFS \u4e0e\u9006\u5411\u8fb9\u754c\u4fdd\u62a4\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"LeetCode 130. \u88ab\u56f4\u7ed5\u7684\u533a\u57df &#x1f4cc; \u9898\u76ee\u63cf\u8ff0 \u7ed9\u4f60\u4e00\u4e2a m x n \u7684\u77e9\u9635 board &#xff0c;\u7531\u82e5\u5e72\u5b57\u7b26 X \u548c O \u7ec4\u6210&#xff0c;\u6355\u83b7 \u6240\u6709 \u88ab\u56f4\u7ed5\u7684\u533a\u57df&#xff1a;\u8fde\u63a5&#xff1a;\u4e00\u4e2a\u5355\u5143\u683c\u4e0e\u6c34\u5e73\u6216\u5782\u76f4\u65b9\u5411\u4e0a\u76f8\u90bb\u7684\u5355\u5143\u683c\u8fde\u63a5\u3002\u533a\u57df&#xff1a;\u8fde\u63a5\u6240\u6709 O \u7684\u5355\u5143\u683c\u6765\u5f62\u6210\u4e00\u4e2a\u533a\u57df\u3002\u56f4\u7ed5&#xff1a;\u5982\u679c\u4e00\u4e2a\u533a\u57df\u4e2d\u7684\u6240\u6709 O \u5355\u5143\u683c\u90fd\u4e0d\u5728\u68cb\u76d8\u7684\u8fb9\u7f18&#xff0c;\u5219\u8be5\u533a\u57df\u88ab\u5305\u56f4\u3002\u8fd9\u6837\u7684\u533a\u57df\u5b8c\u5168\u88ab X \u5355\u5143\u683c\u5305\u56f4\u3002 \u901a\u8fc7","og_url":"https:\/\/www.wsisp.com\/helps\/108484.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-21T13:08:35+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/108484.html","url":"https:\/\/www.wsisp.com\/helps\/108484.html","name":"\u3010Classic 150 \u5237\u9898\u8ba1\u5212\u3011 LeetCode 130. \u88ab\u56f4\u7ed5\u7684\u533a\u57df | C++ \u77e9\u9635 DFS \u4e0e\u9006\u5411\u8fb9\u754c\u4fdd\u62a4\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-21T13:08:35+00:00","dateModified":"2026-09-21T13:08:35+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/108484.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/108484.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/108484.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Classic 150 \u5237\u9898\u8ba1\u5212\u3011 LeetCode 130. \u88ab\u56f4\u7ed5\u7684\u533a\u57df | C++ \u77e9\u9635 DFS \u4e0e\u9006\u5411\u8fb9\u754c\u4fdd\u62a4\u6cd5"}]},{"@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\/108484","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=108484"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/108484\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=108484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=108484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=108484"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=108484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}