Re: [LeetCode] 刷到面試 Grind169 C++已回收

看板Marginalman作者 (彗星雷達)時間2年前 (2023/03/18 15:41), 編輯推噓3(303)
留言6則, 6人參與, 2年前最新討論串9/14 (看更多)
733. Flood Fill easy題 我好爛 我這完全沒想到要怎麼解 你們是寫多少題才能直接自己寫出來啊 class Solution { public: vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int newcolor) { if(image[sr][sc] == newcolor) return image; int m = image.size(); int n = image[0].size(); floodFill(image, sc, sr, m, n, image[sr][sc], newcolor); return image; } private: void floodFill(vector<vector<int>>& image, int x, int y, int m, int n, int origincolor, int newcolor){ if(x<0 || x>=n || y<0 || y>=m) return; if(image[y][x] != origincolor) return; image[y][x] = newcolor; floodFill(image, x+1, y, m, n, origincolor, newcolor); floodFill(image, x-1, y, m, n, origincolor, newcolor); floodFill(image, x, y+1, m, n, origincolor, newcolor); floodFill(image, x, y-1, m, n, origincolor, newcolor); } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.140.197.255 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1679125295.A.738.html

03/18 15:45, 2年前 , 1F
大師
03/18 15:45, 1F

03/18 15:46, 2年前 , 2F
問chatGPT
03/18 15:46, 2F

03/18 15:48, 2年前 , 3F
這題不就搜索 DFS
03/18 15:48, 3F

03/18 15:51, 2年前 , 4F
flood fill就是一種演算法的名字ㄚ 常常用DFS或BFS實作
03/18 15:51, 4F

03/18 15:52, 2年前 , 5F
我很爛 對不起
03/18 15:52, 5F

03/18 16:47, 2年前 , 6F
大師
03/18 16:47, 6F
文章代碼(AID): #1a5MilSu (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1a5MilSu (Marginalman)