4.2---找图的两个节点是否有路径
2015-12-22 16:06
204 查看
//这道题AC了,但是并不确定是否完全正确。此外要注意因为是有向图,所以既要检查a到b,还要检查b到a public class Path { public boolean checkPath(UndirectedGraphNode a, UndirectedGraphNode b) { return checkPath2(a,b) || checkPath2(b,a); } public boolean checkPath2(UndirectedGraphNode a, UndirectedGraphNode b) { boolean res = false; if(a.label == b.label) return true; if(a.neighbors == null) return false; for(UndirectedGraphNode temp : a.neighbors){ if(temp.label == -1){ return false; } else{ temp.label = -1; } if(checkPath(temp,b)){ return true; } } return res; } }
相关文章推荐
- shell 命令
- Swift如何实现代理,block传值
- 手机自动化测试:appium源码分析之bootstrap十三 1
- utf8_bin跟utf8_general_ci的区别
- JAVA RMI远程方法调用简单实例
- 设计模式(二十一)---解释器模式
- 手机自动化测试:appium源码分析之bootstrap十二
- SpringMVC入门实例及详细讲解
- 海康威视 DVR IPC, IOS系统的SDK包。用于二次开发
- 一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- 第七章 注解式控制器的数据验证、类型转换及格式化(2)
- printk的定向问题
- HDOJ 1286 找新朋友
- 用PickerView仿电台频道切换
- Eclipse添加和查看书签
- iOS:你App的设置做对了吗?
- 手机自动化测试:appium源码分析之bootstrap十二
- Class.forName() ClassLoader.loadClass () 区别小议
- 关于DRM文件