We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 877408e commit 0255cebCopy full SHA for 0255ceb
javascript/695-Max Area of Island.js
@@ -0,0 +1,32 @@
1
+var maxAreaOfIsland = function(grid) {
2
+ function find(x, y) {
3
+ if (grid[y] === undefined || grid[y][x] === undefined) {
4
+ return 0;
5
+ }
6
+
7
+ if (grid[y][x] === 0) {
8
9
10
11
+ grid[y][x] = 0;
12
13
+ let square = 1;
14
15
+ square += find(x + 1, y);
16
+ square += find(x - 1, y);
17
+ square += find(x, y + 1);
18
+ square += find(x, y - 1);
19
20
+ return square;
21
22
23
+ let max = 0;
24
25
+ for (let y = 0; y < grid.length; y++) {
26
+ for (let x = 0; x < grid[0].length; x++) {
27
+ max = Math.max(max, find(x, y));
28
29
30
31
+ return max;
32
+};
0 commit comments