Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0255ceb

Browse files
authored
Add 695-Max Area of Island.js
1 parent877408e commit0255ceb

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎javascript/695-Max Area of Island.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
varmaxAreaOfIsland=function(grid){
2+
functionfind(x,y){
3+
if(grid[y]===undefined||grid[y][x]===undefined){
4+
return0;
5+
}
6+
7+
if(grid[y][x]===0){
8+
return0;
9+
}
10+
11+
grid[y][x]=0;
12+
13+
letsquare=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+
returnsquare;
21+
}
22+
23+
letmax=0;
24+
25+
for(lety=0;y<grid.length;y++){
26+
for(letx=0;x<grid[0].length;x++){
27+
max=Math.max(max,find(x,y));
28+
}
29+
}
30+
31+
returnmax;
32+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp