2026-06-01 18:12:40 +08:00
#+ANKI_DECK : study_deck_02
2026-06-01 17:12:10 +08:00
* TODO 0200. Number of Islands :medium:
2026-06-01 02:33:30 +08:00
:PROPERTIES:
2026-06-01 17:22:07 +08:00
:NEETCODE: [[file:../../roadmap.org::*0200. Number of Islands][0200. Number of Islands]]
2026-06-01 02:33:30 +08:00
:END:
2026-06-01 17:22:07 +08:00
Given an ~m x n~ 2D binary grid ~grid~ which represents a map of ~'1'~s (land) and ~ '0'~s (water), return /the number of islands/ .
An *island* is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
*Example 1:*
#+begin_ src
Input: grid = [
["1","1","1","1","0"],
["1","1","0","1","0"],
["1","1","0","0","0"],
["0","0","0","0","0"]
]
Output: 1
#+end_src
*Example 2:*
#+begin_ src
Input: grid = [
["1","1","0","0","0"],
["1","1","0","0","0"],
["0","0","1","0","0"],
["0","0","0","1","1"]
]
Output: 3
#+end_src
*Constraints:*
- ~m == grid.length~
- ~n == grid[i].length~
- ~1 <= m, n <= 300~
- ~grid[i][j]~ is ~'0'~ or ~'1'~ .
2026-06-01 02:39:53 +08:00
** TODO Approach
Write your approach here.
** TODO Python
2026-06-05 22:32:49 +08:00
#+begin_src python :lc-problem 200 :lc-lang python3
2026-06-01 17:22:07 +08:00
class Solution :
def numIslands ( self , grid : List [ List [ str ] ] ) - > int :
2026-06-01 02:39:53 +08:00
#+end_src
** TODO C++
2026-06-05 22:32:49 +08:00
#+begin_src cpp :lc-problem 200
2026-06-01 17:22:07 +08:00
class Solution {
public :
int numIslands ( vector < vector < char > > & grid ) {
}
} ;
2026-06-01 02:33:30 +08:00
#+end_src