Error
|
|
---|---|
@Ibrahim Nash | 6420 |
@blackshadows | 6376 |
@mb1973 | 5578 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@kirtidee18 | 3673 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3412 |
Complete Leaderboard | |
|
|
@codersgroup18 | 714 |
@Manikanta punnam | 579 |
@sriramgoparaju99 | 532 |
@yashkaril4 | 517 |
@praveenbgp6 | 517 |
@prankursharma31 | 489 |
@rdakka | 465 |
@sonamnigam1999 | 441 |
@purohitmn02 | 427 |
@sonamkumari63928 | 426 |
@ShubhankarPandey | 419 |
Complete Leaderboard |
Given a grid consisting of '0's(Water) and '1's(Land). Find the number of islands.
Note: An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically or diagonally i,e in all 8 directions.
Example 1:
Input: grid = {{0,1},{1,0},{1,1},{1,0}} Output: 1 Explanation: The grid is- 0 1 1 0 1 1 1 0 All lands are connected.
Example 2:
Input:
grid = {{0,1,1,1,0,0,0},{0,0,1,1,0,1,0}}
Output:
2
Expanation:
The grid is-
0 1 1 1 0 0 0
0 0 1 1 0 1 0
There are two islands one is colored in blue
and other in orange.
Your Task:
You don't need to read or print anything. Your task is to complete the function numIslands() which takes grid as input parameter and returns the total number of islands.
Expected Time Compelxity: O(n*m)
Expected Space Compelxity: O(n*m)
Constraints:
1 <= n, m <= 500
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes