← 返回 apple 的题目列表Number of Islands II
类型:qbank
You are given an empty m x n grid initially filled with water. We may perform an addLand operation where positions[i] = [ri, ci] turns the cell (ri, ci) into land.
Examples
Example 1:
Input: m = 3, n = 3, positions = [[0,0],[0,1],[1,2],[2,1],[1,1]]
Output: [1,1,2,3,1]
Explanation:
The last addition connects three previously separate islands into one.
Example 2:
Input: m = 1, n = 1, positions = [[0,0]]
Output: [1]
Constraints
1 <= m, n <= 10^4
1 <= m * n <= 10^4
0 <= positions.length <= 10^4
0 <= ri < m
0 <= ci < n