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.
2 parents 877408e + aeee42e commit 758ff65Copy full SHA for 758ff65
javascript/695-Max-Area-Of-Island.js
@@ -0,0 +1,36 @@
1
+/**
2
+ * @param {number[][]} grid
3
+ * @return {number}
4
+ */
5
+var maxAreaOfIsland = function(grid) {
6
+ function find(x, y) {
7
+ if (grid[y] === undefined || grid[y][x] === undefined) {
8
+ return 0;
9
+ }
10
+
11
+ if (grid[y][x] === 0) {
12
13
14
15
+ grid[y][x] = 0;
16
17
+ let square = 1;
18
19
+ square += find(x + 1, y);
20
+ square += find(x - 1, y);
21
+ square += find(x, y + 1);
22
+ square += find(x, y - 1);
23
24
+ return square;
25
26
27
+ let max = 0;
28
29
+ for (let y = 0; y < grid.length; y++) {
30
+ for (let x = 0; x < grid[0].length; x++) {
31
+ max = Math.max(max, find(x, y));
32
33
34
35
+ return max;
36
+};
0 commit comments