From 0255ceb5844e4ac95fb34f2e55d69d2203922c69 Mon Sep 17 00:00:00 2001 From: Farhan Asghar <62025759+farhan523@users.noreply.github.com> Date: Sat, 9 Jul 2022 15:17:12 +0500 Subject: [PATCH 1/2] Add 695-Max Area of Island.js --- javascript/695-Max Area of Island.js | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 javascript/695-Max Area of Island.js diff --git a/javascript/695-Max Area of Island.js b/javascript/695-Max Area of Island.js new file mode 100644 index 000000000..58a099ad5 --- /dev/null +++ b/javascript/695-Max Area of Island.js @@ -0,0 +1,32 @@ +var maxAreaOfIsland = function(grid) { + function find(x, y) { + if (grid[y] === undefined || grid[y][x] === undefined) { + return 0; + } + + if (grid[y][x] === 0) { + return 0; + } + + grid[y][x] = 0; + + let square = 1; + + square += find(x + 1, y); + square += find(x - 1, y); + square += find(x, y + 1); + square += find(x, y - 1); + + return square; + } + + let max = 0; + + for (let y = 0; y < grid.length; y++) { + for (let x = 0; x < grid[0].length; x++) { + max = Math.max(max, find(x, y)); + } + } + + return max; +}; From aeee42e6ad509a9cbdd17b770523faf4556d4674 Mon Sep 17 00:00:00 2001 From: aa0 <71089234+Ahmad-A0@users.noreply.github.com> Date: Sat, 9 Jul 2022 11:37:26 +0100 Subject: [PATCH 2/2] Update and rename 695-Max Area of Island.js to 695-Max-Area-Of-Island.js --- .../{695-Max Area of Island.js => 695-Max-Area-Of-Island.js} | 4 ++++ 1 file changed, 4 insertions(+) rename javascript/{695-Max Area of Island.js => 695-Max-Area-Of-Island.js} (92%) diff --git a/javascript/695-Max Area of Island.js b/javascript/695-Max-Area-Of-Island.js similarity index 92% rename from javascript/695-Max Area of Island.js rename to javascript/695-Max-Area-Of-Island.js index 58a099ad5..5312e5160 100644 --- a/javascript/695-Max Area of Island.js +++ b/javascript/695-Max-Area-Of-Island.js @@ -1,3 +1,7 @@ +/** + * @param {number[][]} grid + * @return {number} + */ var maxAreaOfIsland = function(grid) { function find(x, y) { if (grid[y] === undefined || grid[y][x] === undefined) {
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: