← 返回题库
中级

岛屿的最大面积

未完成
中级参考 代码结构已给出,请填写 ____ 处
from collections import deque
def solve():
    def maxAreaOfIsland(____):
        if not grid:
            return ____
        m, n = len(____), len(____)
        max_area = ____
        for i in range(____):
            for j in range(____):
                if grid[i][j] == ____:
                    area = ____
                    queue = deque([(____)])
                    grid[i][j] = ____
                    while queue:
                        x, y = queue.popleft()
                        area += ____
                        for dx, dy in [(____, ____), (____), (____, ____), (____, -____)]:
                            nx, ny = x + dx, y + dy
                            if ____ <= nx < m and ____ <= ny < n and grid[nx][ny] == ____:
                                grid[nx][ny] = ____
                                queue.append((____))
                    max_area = max(____)
        return max_area
    grid = [[____,____,____,____,____,____,____,____,____,____,____,____,____],[____,____,____,____,____,____,____,____,____,____,____,____,____],[____,____,____,____,____,____,____,____,____,____,____,____,____],[____,____,____,____,____,____,____,____,____,____,____,____,____],[____,____,____,____,____,____,____,____,____,____,____,____,____],[____,____,____,____,____,____,____,____,____,____,____,____,____],[____,____,____,____,____,____,____,____,____,____,____,____,____],[____,____,____,____,____,____,____,____,____,____,____,____,____]]
    print(maxAreaOfIsland(____))

示例

输入
solve()
期望输出
6
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码