File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
docs/data-structure/array Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -1732,6 +1732,31 @@ func islandPerimeter(grid [][]int) int {
1732
1732
}
1733
1733
```
1734
1734
1735
+ #### ** Java**
1736
+
1737
+ ``` java
1738
+ class Solution {
1739
+ public int islandPerimeter (int [][] grid ) {
1740
+ if (grid == null || grid. length <= 0 || grid[0 ] == null || grid[0 ]. length <= 0 ) return 0 ;
1741
+ int height = grid. length;
1742
+ int width = grid[0 ]. length;
1743
+
1744
+ int result = 0 ;
1745
+
1746
+ for (int i = 0 ; i < height; i++ ) {
1747
+ for (int j = 0 ; j < width; j++ ) {
1748
+ if (grid[i][j] == 1 ) {
1749
+ if (i == 0 || grid[i - 1 ][j] == 0 ) result++ ;
1750
+ if (j == 0 || grid[i][j - 1 ] == 0 ) result++ ;
1751
+ }
1752
+ }
1753
+ }
1754
+
1755
+ return result * 2 ;
1756
+ }
1757
+ }
1758
+ ```
1759
+
1735
1760
<!-- tabs:end -->
1736
1761
1737
1762
## 485. 最大连续1的个数
You can’t perform that action at this time.
0 commit comments