LintCode – Ladder4 Breadth First Search

LintCode – Ladder4 Breadth First Search

大家好,又见面了,我是全栈君。

Nov. 5th

Number of islands

Des: 2D matrix
Solution:
1. iterate through all the elements of the 2D matrix
2.if v == 1 ->
bfs through the one hop neighbors of the vertex
if all the neightbors == 0
result + 1
if any one of the neighbors == 1
bfs the neighbor
result + 1
3.return the result

Quesiton:
1.如何确定一个2D matrix 的行数和列数? -> 使用vertex s作为起点, (s-1) / n = 行数, (s-1) % n = 列数
n = grid.length m = grid[0].length
2.如何遍历

1066857-20171106011104759-1426160239.png

转载于:https://www.cnblogs.com/kong-xy/p/7791461.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/108054.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号