今際の国の呵呵君
Saturday, August 26, 2017
[LeetCode]Number of Connected Components in an Undirected Graph
DFS的问题,从每个节点开始DFS,如果之间访问过就说明不是新的component,否则的话mark所有这次DFS能到达的节点,就是新的component,记录数量即可,代码如下:
链接性的题目Union Find也完全可以,Union Find的做法可以参考
Friend Circle
。
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment