Route Between Two Nodes in Graph
来源:互联网 发布:山东理工大学网络教育 编辑:程序博客网 时间:2024/05/23 15:03
public class Solution { public boolean hasRoute(ArrayList<DirectedGraphNode> graph, DirectedGraphNode s, DirectedGraphNode t) { if (s == t) { return true; } Queue<DirectedGraphNode> queue = new LinkedList<>(); HashSet<DirectedGraphNode> set = new HashSet<>(); queue.offer(s); set.add(s); while (!queue.isEmpty()) { DirectedGraphNode node = queue.poll(); for (DirectedGraphNode neighbor : node.neighbors) { // t must be a node in the graph, so we can compare if node's neighbor is equal to t if (neighbor == t) { return true; } if (set.add(neighbor)) { queue.offer(neighbor); } } } return false; }}
0 0
- lintcode:Route Between Two Nodes in Graph
- DFS-----Route Between Two Nodes in Graph
- #176 Route Between Two Nodes in Graph
- Route Between Two Nodes in Graph
- Route Between Two Nodes in Graph
- Lintcode176 Route Between Two Nodes in Graph solution 题解
- 176.Route Between Two Nodes in Graph-图中两个点之间的路线(中等题)
- 4.1 Route Between Nodes
- Finding Path/Route Between two points on MapKit in iPhone
- find distance between two nodes in a binary tree
- Lowest Common Ancestor (LCA) of two nodes in graph
- How To Get Min-Cost Between two points in graph (Dijkstra’s algorithm)
- Finding all possible simple paths (paths without cycles) between two vertices in a graph
- Find the distance between two nodes
- Swap Two Nodes in Linked List
- LintCode:Swap Two Nodes in Linked List
- #511 Swap Two Nodes in Linked List
- Swap Two Nodes in Linked List
- awk精编
- Java读取excel数据并用Arraylist存储
- go语言快速入门:自动化测试(17)
- Leetcode Graph Valid Tree
- cocos2dX中c++和lua的交互-1
- Route Between Two Nodes in Graph
- Effective Java 读书笔记——42:慎用可变参数
- ceres solver使用
- 技术人成长百科指南:给你一束光,路在你脚下
- JAVA基础面试题
- 现代微积分何时传入中国?
- LinuxLog分析常用组合命令
- 安卓基础面试题
- 安卓高级面试题