aboutsummaryrefslogtreecommitdiff
path: root/other/max_area_island.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/max_area_island.cpp')
-rw-r--r--other/max_area_island.cpp24
1 files changed, 0 insertions, 24 deletions
diff --git a/other/max_area_island.cpp b/other/max_area_island.cpp
deleted file mode 100644
index aad8b2d..0000000
--- a/other/max_area_island.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "leetcode.h"
-
-class Solution {
-public:
- int maxAreaOfIsland(vector<vector<int>> &grid) {
- int ans = 0;
- n = grid.size(), m = grid[0].size();
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- if (grid[i][j])
- ans = max(ans, helper(i, j, grid));
- return ans;
- }
-
-private:
- int n = 0, m = 0;
- int helper(int i, int j, vector<vector<int>> &grid) {
- if (i < 0 || j < 0 || i >= n || j >= m || !grid[i][j])
- return 0;
- grid[i][j] = 0;
- return 1 + helper(i - 1, j, grid) + helper(i, j - 1, grid) +
- helper(i + 1, j, grid) + helper(i, j + 1, grid);
- }
-};