当前位置:网站首页>网格(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. 岛屿的最大面积
边栏推荐
- Microbial health network, how to restore microbial communities
- Explain in detail the communication mode between arm A7 and risc-v e907 on Quanzhi v853
- 网络安全-beef
- Anta DTC | Anta transformation, building a growth flywheel that is not only FILA
- CTF练习
- Debezium series: MySQL tombstone event
- Sword finger offer 27 Image of binary tree
- 数字藏品加速出圈,MarsNFT助力多元化文旅经济!
- Early childhood education industry of "screwing bar": trillion market, difficult to be a giant
- Unity dynamically merges mesh textures
猜你喜欢

Digital collections accelerated out of the circle, and marsnft helped diversify the culture and tourism economy!

Database daily question --- day 22: last login

Software test classification

Line test - graphic reasoning - 4 - alphabetic class

行测-图形推理-8-图群类

iNFTnews | NFT技术的广泛应用及其存在的问题

Cases of agile innovation and transformation of consumer goods enterprises

数据库每日一题---第22天:最后一次登录

Innovation today | five key elements for enterprises to promote innovation

The wonderful relationship between message queue and express cabinet
随机推荐
Personal statement of testers from Shuangfei large factory: is education important for testers?
Line test - graphic reasoning - 3 - symmetric graphic class
Brush question 4
It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
Gbu1510-asemi power supply special 15A rectifier bridge gbu1510
7-18 simple simulation of banking business queue
微生物健康網,如何恢複微生物群落
LeetCode206. Reverse linked list [double pointer and recursion]
行测-图形推理-1-汉字类
Interview questions: how to test app performance?
Innovation today | five key elements for enterprises to promote innovation
What is ADC sampling rate (Hz) and how to calculate it
Sword finger offer 27 Image of binary tree
Leetcode94. Middle order traversal of binary trees
行测-图形推理-5-一笔画类
U盘拷贝东西时,报错卷错误,请运行chkdsk
关于海康ipc的几个参数
消息队列与快递柜之间妙不可言的关系
2021-01-12
Locate to the bottom [easy to understand]