keshavsingh4522 / hacktoberfest

Submit Just 4 PRs to earn SWAGS and Tshirts🔥
https://hacktoberfest.digitalocean.com/
Creative Commons Zero v1.0 Universal
844 stars 3.91k forks source link

Add Leetcode Number Of islands Solution #4483

Open nizar787 opened 1 year ago

nizar787 commented 1 year ago

Is your feature request related to a problem? Please describe.

Describe the solution you'd like

Describe alternatives you've considered

Additional context

bhalerao-2002 commented 1 year ago

Hello @nizar787 , I can add that solution, Assign me this issue under hacktoberfest

sajithsojan commented 1 year ago

please review my code

alipsa2000 commented 1 year ago

This is the code can you please review this code

include

include

using namespace std; class Solution { public: int numIslands(vector<vector>& grid) { if (grid.empty() || grid[0].empty()) { return 0; } int numIslands = 0; int m = grid.size(); int n = grid[0].size(); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (grid[i][j] == '1') { numIslands++; dfs(grid, i, j); } } } return numIslands; } private: void dfs(vector<vector>& grid, int i, int j) { if (i < 0 || i >= grid.size() || j < 0 || j >= grid[0].size() || grid[i][j] != '1') { return; } grid[i][j] = '0'; dfs(grid, i - 1, j); dfs(grid, i + 1, j); dfs(grid, i, j - 1); dfs(grid, i, j + 1); } };

PRITISH212121 commented 1 year ago

i have solved this problem before,i m attaching my leetcode profile,please assign it to me https://leetcode.com/pritishyo10/

navya975 commented 1 year ago

I have solved this problem before,I am attaching my leetcode profile,please assign it to me https://leetcode.com/navya975/

mrinalproxy commented 12 months ago

assigned this problem to me