当前位置:网站首页>网格(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. 岛屿的最大面积
边栏推荐
- Transform XL translation
- Software test classification
- LeetCode707. Design linked list
- 行测-图形推理-4-字母类
- QT graphicsview graphical view usage summary with flow chart development case prototype
- 微信论坛交流小程序系统毕业设计毕设(7)中期检查报告
- 微信论坛交流小程序系统毕业设计毕设(4)开题报告
- Line test - graphic reasoning -5- one stroke class
- Line test - graphic reasoning - 6 - similar graphic classes
- 双非大厂测试员亲述:对测试员来说,学历重要吗?
猜你喜欢
微生物健康網,如何恢複微生物群落
Line test - graphic reasoning - 3 - symmetric graphic class
Anta DTC | Anta transformation, building a growth flywheel that is not only FILA
行测-图形推理-6-相似图形类
Unity and webgl love each other
Leetcode206. Reverse linked list
PCL .vtk文件与.pcd的相互转换
Database daily question --- day 22: last login
行测-图形推理-1-汉字类
Are the microorganisms in the intestines the same as those on the skin?
随机推荐
面试百问:如何测试App性能?
Circumvention Technology: Registry
DTC社群运营怎么做?
Exploratory data analysis of heartbeat signal
ArcGIS:字段赋值_属性表字段计算器(Field Calculator)依据条件为字段赋值
Line measurement - graphic reasoning -9- line problem class
Brush question 4
网络安全-beef
Introduction to anomaly detection
Leetcode94. Middle order traversal of binary trees
6-3 find the table length of the linked table
PCL . VTK files and Mutual conversion of PCD
Sword finger offer 28 Symmetric binary tree
Clean C disk
Anta DTC | Anta transformation, building a growth flywheel that is not only FILA
LeetCode707. Design linked list
Debezium series: source code reading snapshot reader
Line test graph reasoning graph group class
Digital collections accelerated out of the circle, and marsnft helped diversify the culture and tourism economy!
Are the microorganisms in the intestines the same as those on the skin?