当前位置:网站首页>网格(Grid)
网格(Grid)
2022-07-07 21:50:00 【Yake1965】
Grid
- [463. 岛屿的周长](https://leetcode.cn/problems/island-perimeter/)
- [200. 岛屿数量](https://leetcode.cn/problems/number-of-islands/)
- [1905. 统计子岛屿](https://leetcode.cn/problems/count-sub-islands/)
- [695. 岛屿的最大面积](https://leetcode.cn/problems/max-area-of-island/)
- [1254. 统计封闭岛屿的数目](https://leetcode.cn/problems/number-of-closed-islands/)
- [827. 最大人工岛](https://leetcode.cn/problems/making-a-large-island/)
- [1568. 使陆地分离的最少天数](https://leetcode.cn/problems/minimum-number-of-days-to-disconnect-island/)
- [417. 太平洋大西洋水流问题](https://leetcode.cn/problems/pacific-atlantic-water-flow/)
- [剑指 Offer II 105. 岛屿的最大面积](https://leetcode.cn/problems/ZL6zAn/)
463. 岛屿的周长
class Solution {
int[] a = {
0, 1, 0, -1}, b = {
1, 0, -1, 0};
public int islandPerimeter(int[][] grid) {
int n = grid.length, m = grid[0].length, ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (grid[i][j] == 0) continue;
for (int k = 0; k < 4; k++) {
int x = i + a[k], y = j + b[k];
if (x < 0 || x >= n || y < 0 || y >= m || grid[x][y] == 0) ans += 1;
}
}
}
return ans;
}
}
200. 岛屿数量
class Solution {
int m, n;
public int numIslands(char[][] grid) {
m = grid.length;
n = grid[0].length;
int ans = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (grid[i][j] == '1') {
ans++;
dfs(grid, i, j);
}
}
}
return ans;
}
void dfs(char[][] grid, int i, int j) {
if (i < 0 || j < 0 || i >= m || j >= n || grid[i][j] == '0') return;
grid[i][j] = '0';
dfs(grid, i - 1, j);
dfs(grid, i + 1, j);
dfs(grid, i, j - 1);
dfs(grid, i, j + 1);
}
}
1905. 统计子岛屿
695. 岛屿的最大面积
1254. 统计封闭岛屿的数目
827. 最大人工岛
1568. 使陆地分离的最少天数
417. 太平洋大西洋水流问题
剑指 Offer II 105. 岛屿的最大面积
边栏推荐
- ArcGIS:字段赋值_属性表字段计算器(Field Calculator)依据条件为字段赋值
- 2021-01-11
- About idea cannot find or load the main class
- Brush question 4
- 行测-图形推理-8-图群类
- 关于海康ipc的几个参数
- OC variable parameter transfer
- [network] Introduction to C language
- Debezium系列之:支持 mysql8 的 set role 語句
- Microbial health network, how to restore microbial communities
猜你喜欢
行测-图形推理-6-相似图形类
Line test - graphic reasoning - 6 - similar graphic classes
Knowledge drop - PCB manufacturing process flow
U盘拷贝东西时,报错卷错误,请运行chkdsk
Innovation today | five key elements for enterprises to promote innovation
微信论坛交流小程序系统毕业设计毕设(1)开发概要
Explain in detail the communication mode between arm A7 and risc-v e907 on Quanzhi v853
Line test - graphic reasoning - 2 - black and white lattice class
I wish you all the best and the year of the tiger
消费品企业敏捷创新转型案例
随机推荐
Build an "immune" barrier in the cloud to prepare your data
数字藏品加速出圈,MarsNFT助力多元化文旅经济!
Guessing game (read data from file)
Innovation today | five key elements for enterprises to promote innovation
安踏DTC | 安踏转型,构建不只有FILA的增长飞轮
Digital transformation: five steps to promote enterprise progress
消费品企业敏捷创新转型案例
Exploratory data analysis of heartbeat signal
ArcGIS:字段赋值_属性表字段计算器(Field Calculator)依据条件为字段赋值
Brush question 4
定位到最底部[通俗易懂]
Some parameters of Haikang IPC
Leetcode19. Delete the penultimate node of the linked list [double pointer]
Line test - graphic reasoning - 3 - symmetric graphic class
It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
How to operate DTC community?
iNFTnews | Web5 vs Web3:未来是一个过程,而不是目的地
V20变频器手自动切换(就地远程切换)的具体方法示例
Sword finger offer 27 Image of binary tree
微信论坛交流小程序系统毕业设计毕设(1)开发概要