End of Year Sale: Use Coupon Code END2025 to Get Extra 25% Off.
00DAYS
:
00HOURS
:
00MINUTES
:
00SECONDS
Leetcode Problem 1254. Number of Closed Islands
1254. Number of Closed Islands
Leetcode Solutions
Depth First Search (DFS) to Find Closed Islands
Initialize a count variable to 0 to keep track of closed islands.
Create a visited 2D array to mark visited cells.
Iterate over each cell in the grid.
a. If the cell is a land cell (0) and not visited, perform DFS from this cell.
b. If DFS returns true (island is closed), increment the count.