注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
https://leetcode.com/problems/friend-circles/solution/
https://leetcode.com/problems/number-of-islands/solution/
根据这两道题的官方solution, 都是 'find number of connected nodes in a un-directed graph', 都可以用dfs 解。但是解法竟然不一样, number of islands 需要double loop, friends circle就一个loop. 为啥?
另外如果我用number of islands 来解friend circle, 这个case 过不了. 为啥一下是1个朋友圈? 三个角不是孤立的吗? 按照'number of connected nodes in un-directed graph', 这个明明是4个岛啊。谁能解释一下这两道题思路区别在哪里,为啥代码这么不一样?
Input:[[1,0,0,1],[0,1,1,0],[0,1,1,1],[1,0,1,1]]
Output:[color=rgb(208, 84, 81) !important]4
Expected:[color=rgb(68, 157, 68) !important]1
|