Skip to content

Commit 758ff65

Browse files
authored
Merge pull request neetcode-gh#431 from farhan523/patch-1
Add 695-Max Area of Island.js
2 parents 877408e + aeee42e commit 758ff65

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

javascript/695-Max-Area-Of-Island.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
return 0;
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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy