Google 2016 面试题5 | 岛屿计数2

题目描述

给出一个m行n列的网格地图,每个位置为0或1,0表示海水1表示陆地。一开始地图全为0(没有陆地)。每次在一个位置加入一块陆地,返回此时地图中陆地的总块数(相邻陆地统计时为同一块陆地)。
Example:
操作#1: addLand(0, 0) turns the water at grid[0][0] into a land.
leetcode
操作#2: addLand(0, 1) turns the water at grid[0][1] into a land.
leetcode
操作#3: addLand(1, 2) turns the water at grid[1][2] into a land.
leetcode
操作#4: addLand(2, 1) turns the water at grid[2][1] into a land.
leetcode
返回答案数组: [1, 1, 2, 3]
你可以做到复杂度O(k log mn)吗?其中k为操作次数。

分析解答

对于一个静态的地图,统计岛屿个数可以使用dfs(

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值