{"id":254,"date":"2022-09-21T15:08:17","date_gmt":"2022-09-21T07:08:17","guid":{"rendered":"https:\/\/courtship.top\/?p=254"},"modified":"2022-09-21T15:08:17","modified_gmt":"2022-09-21T07:08:17","slug":"733-%e5%9b%be%e5%83%8f%e6%b8%b2%e6%9f%93","status":"publish","type":"post","link":"https:\/\/courtship.top\/index.php\/2022\/09\/21\/733-%e5%9b%be%e5%83%8f%e6%b8%b2%e6%9f%93\/","title":{"rendered":"733.\u56fe\u50cf\u6e32\u67d3"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode.cn\/problems\/flood-fill\/\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/leetcode.cn\/problems\/flood-fill\/<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution {\npublic:\n    vector&lt;vector&lt;int&gt;&gt; floodFill(vector&lt;vector&lt;int&gt;&gt;&amp; image, int sr, int sc, int newColor) {\n        int curcolor = image&#91;sr]&#91;sc];\n        if(newColor == image&#91;sr]&#91;sc])\n            return image;\n        else\n            dfs(image,sr,sc,curcolor,newColor);\n        return image;\n    }\n\n    void dfs(vector&lt;vector&lt;int&gt;&gt;&amp; image,int sr,int sc,int curcolor,int newcolor){\n        int rs = image.size();       \/\/sr\u8fb9\u754c\n        int rc = image&#91;0].size();   \/\/sc\u8fb9\u754c\n        if(image&#91;sr]&#91;sc] == curcolor){\n\/\/\u5982\u679cimage\u4e2d\u6709\u548c\u521d\u503c\u4e00\u6837\u7684\u624d\u8fdb\u884c\u641c\u7d22 \u641c\u7d22\u4e3a\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\u5e76\u4e14\u5b58\u5728\u8fb9\u754c\u503c\n            image&#91;sr]&#91;sc] = newcolor; \/\/\u8d4b\u503c\n            if(sr - 1 &gt;= 0)      dfs(image,sr - 1,sc,curcolor,newcolor);\n            if(sr + 1 &lt;= rs - 1) dfs(image,sr + 1,sc,curcolor,newcolor);\n            if(sc - 1 &gt;= 0)      dfs(image,sr,sc - 1,curcolor,newcolor);\n            if(sc + 1 &lt;= rc - 1) dfs(image,sr,sc + 1,curcolor,newcolor);\n        }\n\n    }\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode.cn\/problems\/flood-fill\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-254","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts\/254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/comments?post=254"}],"version-history":[{"count":0,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts\/254\/revisions"}],"wp:attachment":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/media?parent=254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/categories?post=254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/tags?post=254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}