网站建设后的专人维护,wordpress的安装步骤,如何建网站费用多少,工业设计和产品设计的区别目录 Leetcode695. 岛屿的最大面积Leetcode1020. 飞地的数量Leetcode130. 被围绕的区域Leetcode417. 太平洋大西洋水流问题Leetcode827.最大人工岛 Leetcode695. 岛屿的最大面积 文章链接#xff1a;代码随想录 题目链接#xff1a;695. 岛屿的最大面积 思路#xff1a;dfs … 目录 Leetcode695. 岛屿的最大面积Leetcode1020. 飞地的数量Leetcode130. 被围绕的区域Leetcode417. 太平洋大西洋水流问题Leetcode827.最大人工岛 Leetcode695. 岛屿的最大面积 文章链接代码随想录 题目链接695. 岛屿的最大面积 思路dfs 
class Solution {
public:int count;int dir[4][2]  {1, 0, -1, 0, 0, 1, 0, -1};void dfs(vectorvectorint grid, vectorvectorbool visited, int x, int y){for (int i  0; i  4; i){int nex  x  dir[i][0];int ney  y  dir[i][1];if (nex  0 || nex  grid.size() || ney  0 || ney  grid[0].size()) continue;if (!visited[nex][ney]  grid[nex][ney]  1){visited[nex][ney]  true;count;dfs(grid, visited, nex, ney);}}}int maxAreaOfIsland(vectorvectorint grid) {int result  0;vectorvectorbool visited(grid.size(), vectorbool(grid[0].size(), 0));for (int i  0; i  grid.size(); i){for (int j  0; j  grid[0].size(); j){if (!visited[i][j]  grid[i][j]  1){visited[i][j]  true;count  1;dfs (grid, visited, i, j);result  max(result, count);}}}return result;}};bfs 
class Solution {
public:int count;int dir[4][2]  {1, 0, -1, 0, 0, 1, 0, -1};void bfs(vectorvectorint grid, vectorvectorbool visited, int x, int y){queuepairint, int que;que.push({x, y});while(!que.empty()){pairint, int cur  que.front();que.pop();for (int i  0; i  4; i){int nex  cur.first  dir[i][0];int ney  cur.second  dir[i][1];if (nex  0 || nex  grid.size() || ney  0 || ney  grid[0].size()) continue;if (!visited[nex][ney]  grid[nex][ney]  1){visited[nex][ney]  true;count;que.push({nex, ney});}}}}int maxAreaOfIsland(vectorvectorint grid) {int result  0;vectorvectorbool visited(grid.size(), vectorbool(grid[0].size(), 0));for (int i  0; i  grid.size(); i){for (int j  0; j  grid[0].size(); j){if (!visited[i][j]  grid[i][j]  1){visited[i][j]  true;count  1;bfs (grid, visited, i, j);result  max(result, count);}}}return result;}};Leetcode1020. 飞地的数量 文章链接代码随想录 题目链接1020. 飞地的数量 思路dfs 
class Solution {
public:int count  0;int dir[4][2]  {1, 0, -1, 0, 0, 1, 0, -1};void dfs(vectorvectorint grid, int x, int y){grid[x][y]  0;count;for (int i  0; i  4; i){int nex  x  dir[i][0];int ney  y  dir[i][1];if (nex  0 || nex  grid.size() || ney  0 || ney  grid[0].size()) continue;if (grid[nex][ney]  1) dfs(grid, nex, ney);}return ;}int numEnclaves(vectorvectorint grid) {int m  grid.size();int n  grid[0].size();int result  0;for (int i  0; i  m; i){if(grid[i][0]  1) dfs(grid, i, 0);if(grid[i][n - 1]  1) dfs(grid, i, n - 1);}for (int j  0; j  n; j){if (grid[0][j]  1) dfs(grid, 0, j);if (grid[m - 1][j]  1) dfs(grid, m - 1, j);}for (int i  0; i  m; i){for (int j  0; j  n; j){if (grid[i][j]  1) {count  0;dfs(grid, i, j);result  count;}}}return result;}
};Leetcode130. 被围绕的区域 文章链接代码随想录 题目链接130. 被围绕的区域 思路dfs 
class Solution {
public:int dir[4][2]  {1, 0, -1, 0, 0, 1, 0, -1};void dfs(vectorvectorchar board, int x, int y){board[x][y]  A;for (int i  0; i  4; i){int nex  x  dir[i][0];int ney  y  dir[i][1];if (nex  0 || nex  board.size() || ney  0 || ney  board[0].size()) continue;if (board[nex][ney]  O) dfs(board, nex, ney);}}    void solve(vectorvectorchar board) {int m  board.size();int n  board[0].size();for (int i  0; i  m; i){if (board[i][0]  O) dfs(board, i, 0);if (board[i][n - 1]  O) dfs(board, i, n - 1);}for (int j  0; j  n; j){if (board[0][j]  O) dfs(board, 0, j);if (board[m - 1][j]  O) dfs(board, m - 1, j);}for (int i  0; i  m; i){for (int j  0; j  n; j){if (board[i][j]  O) board[i][j]  X;if (board[i][j]  A) board[i][j]  O;}}}
};Leetcode417. 太平洋大西洋水流问题 文章链接代码随想录 题目链接417. 太平洋大西洋水流问题 思路注意终止条件 if (visited[x][y]) return ; 
class Solution {
public:int dir[4][2]  {1, 0, -1, 0, 0, 1, 0, -1};void dfs(vectorvectorint heights, vectorvectorbool visited, int x, int y){// 注意终止条件if (visited[x][y]) return ;visited[x][y]  true;for (int i  0; i  4; i){int nex  x  dir[i][0];int ney  y  dir[i][1];if (nex  0 || nex  heights.size() || ney  0 || ney  heights[0].size()) continue;if (heights[x][y]  heights[nex][ney]) dfs(heights, visited, nex, ney);}}vectorvectorint pacificAtlantic(vectorvectorint heights) {int m  heights.size();int n  heights[0].size();vectorvectorbool pacific(m, vectorbool(n, false));vectorvectorbool atlantic(m, vectorbool(n, false));vectorvectorint result;for (int i  0; i  m; i){dfs(heights, pacific, i, 0);dfs(heights, atlantic, i, n - 1);}for (int j  0; j  n; j){dfs(heights, pacific, 0, j);dfs(heights, atlantic, m - 1, j);}for (int i  0; i  m; i){for (int j  0; j  n; j){if (pacific[i][j]  atlantic[i][j]) result.push_back({i, j});}}return result;}
};Leetcode827.最大人工岛 文章链接代码随想录 题目链接827.最大人工岛 思路dfs先用map记录原有的每块陆地的大小再在0处遍历连接陆地选择最大值。 
class Solution {
public:int count;int mark  2;int dir[4][2]  {1, 0, -1, 0, 0, 1, 0, -1};void dfs(vectorvectorint grid, vectorvectorbool visited, int x, int y){if (visited[x][y] || grid[x][y]  0) return ;visited[x][y]  true;count;grid[x][y]  mark;for (int i  0; i  4; i){int nex  x  dir[i][0];int ney  y  dir[i][1];if (nex  0 || nex  grid.size() || ney  0 || ney  grid[0].size()) continue;dfs(grid, visited, nex, ney);}}int largestIsland(vectorvectorint grid) {int m  grid.size();int n  grid[0].size();vectorvectorbool visited(m, vectorbool(n, false));unordered_mapint, int gridNum;bool isAllGrid  true;int result  0;for (int i  0; i  m; i){for (int j  0; j  n; j){if (grid[i][j]  0) isAllGrid  false;if (!visited[i][j]  grid[i][j]  1){count  0;dfs(grid, visited, i, j);gridNum[mark]  count;mark;}}}// cout  count  endl;// cout  gridNum[2]  endl;if (isAllGrid) return n * m;unordered_setint visitedGrid;for (int i  0; i  m; i){for (int j  0; j  n; j){visitedGrid.clear();if (grid[i][j]  0){count  1;for (int k  0; k  4; k){int nex  i  dir[k][0];int ney  j  dir[k][1];if (nex  0 || nex  grid.size() || ney  0 || ney  grid[0].size()) continue;if (visitedGrid.count(grid[nex][ney])  0){count  gridNum[grid[nex][ney]];visitedGrid.insert(grid[nex][ney]);}}result  max(result, count);}}}return result;}
};图论第二天打卡整体来说套路感挺重的理解和做起来挺简单的但写多了也头晕哈哈加油 文章转载自: http://www.morning.ygwbg.cn.gov.cn.ygwbg.cn http://www.morning.jgcxh.cn.gov.cn.jgcxh.cn http://www.morning.cmcjp.cn.gov.cn.cmcjp.cn http://www.morning.lgcqj.cn.gov.cn.lgcqj.cn http://www.morning.mstrb.cn.gov.cn.mstrb.cn http://www.morning.fcxt.cn.gov.cn.fcxt.cn http://www.morning.nzkkh.cn.gov.cn.nzkkh.cn http://www.morning.24vy.com.gov.cn.24vy.com http://www.morning.phtqr.cn.gov.cn.phtqr.cn http://www.morning.ffhlh.cn.gov.cn.ffhlh.cn http://www.morning.fxjnn.cn.gov.cn.fxjnn.cn http://www.morning.qqnp.cn.gov.cn.qqnp.cn http://www.morning.qgcfb.cn.gov.cn.qgcfb.cn http://www.morning.njfgl.cn.gov.cn.njfgl.cn http://www.morning.rkzk.cn.gov.cn.rkzk.cn http://www.morning.lqjpb.cn.gov.cn.lqjpb.cn http://www.morning.fykrm.cn.gov.cn.fykrm.cn http://www.morning.dnhdp.cn.gov.cn.dnhdp.cn http://www.morning.nkrmh.cn.gov.cn.nkrmh.cn http://www.morning.rghkg.cn.gov.cn.rghkg.cn http://www.morning.httpm.cn.gov.cn.httpm.cn http://www.morning.rhpgk.cn.gov.cn.rhpgk.cn http://www.morning.hjlwt.cn.gov.cn.hjlwt.cn http://www.morning.fkwgk.cn.gov.cn.fkwgk.cn http://www.morning.rfxyk.cn.gov.cn.rfxyk.cn http://www.morning.hpxxq.cn.gov.cn.hpxxq.cn http://www.morning.wgqtj.cn.gov.cn.wgqtj.cn http://www.morning.xsqbx.cn.gov.cn.xsqbx.cn http://www.morning.bmyrl.cn.gov.cn.bmyrl.cn http://www.morning.dqxph.cn.gov.cn.dqxph.cn http://www.morning.gbybx.cn.gov.cn.gbybx.cn http://www.morning.rnht.cn.gov.cn.rnht.cn http://www.morning.jzccn.cn.gov.cn.jzccn.cn http://www.morning.zntf.cn.gov.cn.zntf.cn http://www.morning.wrbx.cn.gov.cn.wrbx.cn http://www.morning.pkwwq.cn.gov.cn.pkwwq.cn http://www.morning.ttfh.cn.gov.cn.ttfh.cn http://www.morning.ysjjr.cn.gov.cn.ysjjr.cn http://www.morning.cwznh.cn.gov.cn.cwznh.cn http://www.morning.ltffk.cn.gov.cn.ltffk.cn http://www.morning.xgcwm.cn.gov.cn.xgcwm.cn http://www.morning.srwny.cn.gov.cn.srwny.cn http://www.morning.mtmph.cn.gov.cn.mtmph.cn http://www.morning.burpgr.cn.gov.cn.burpgr.cn http://www.morning.pngfx.cn.gov.cn.pngfx.cn http://www.morning.zpzys.cn.gov.cn.zpzys.cn http://www.morning.cfqyx.cn.gov.cn.cfqyx.cn http://www.morning.hjjfp.cn.gov.cn.hjjfp.cn http://www.morning.ey3h2d.cn.gov.cn.ey3h2d.cn http://www.morning.ylsxk.cn.gov.cn.ylsxk.cn http://www.morning.lmhwm.cn.gov.cn.lmhwm.cn http://www.morning.gwsfq.cn.gov.cn.gwsfq.cn http://www.morning.yqlrq.cn.gov.cn.yqlrq.cn http://www.morning.xglgm.cn.gov.cn.xglgm.cn http://www.morning.qwmsq.cn.gov.cn.qwmsq.cn http://www.morning.mgwdp.cn.gov.cn.mgwdp.cn http://www.morning.dyhlm.cn.gov.cn.dyhlm.cn http://www.morning.tkztx.cn.gov.cn.tkztx.cn http://www.morning.fosfox.com.gov.cn.fosfox.com http://www.morning.mcbqq.cn.gov.cn.mcbqq.cn http://www.morning.youyouling.cn.gov.cn.youyouling.cn http://www.morning.mxhgy.cn.gov.cn.mxhgy.cn http://www.morning.cczzyy.com.gov.cn.cczzyy.com http://www.morning.gydsg.cn.gov.cn.gydsg.cn http://www.morning.bsghk.cn.gov.cn.bsghk.cn http://www.morning.plwfx.cn.gov.cn.plwfx.cn http://www.morning.qieistand.com.gov.cn.qieistand.com http://www.morning.yqsr.cn.gov.cn.yqsr.cn http://www.morning.lnbcg.cn.gov.cn.lnbcg.cn http://www.morning.gtbjf.cn.gov.cn.gtbjf.cn http://www.morning.huihuangwh.cn.gov.cn.huihuangwh.cn http://www.morning.dspqc.cn.gov.cn.dspqc.cn http://www.morning.zmlbq.cn.gov.cn.zmlbq.cn http://www.morning.zpfqh.cn.gov.cn.zpfqh.cn http://www.morning.ywgrr.cn.gov.cn.ywgrr.cn http://www.morning.kwqwp.cn.gov.cn.kwqwp.cn http://www.morning.ywxln.cn.gov.cn.ywxln.cn http://www.morning.kqkmx.cn.gov.cn.kqkmx.cn http://www.morning.skkln.cn.gov.cn.skkln.cn http://www.morning.yysqz.cn.gov.cn.yysqz.cn