[lintcode] - 391 Number of Airplanes in the Sky
2016-01-27 09:53
405 查看
easy难度的题,基本上是不允许错的,也必须10分钟内做出来。
思路很简单,递归至最深处将结果保存即可。
思路很简单,递归至最深处将结果保存即可。
/** * @author: decaywood * @date: 2016/1/27 9:30 * * Given a binary tree, return all root-to-leaf paths. * * Example * Given the following binary tree: * * 1 * / \ * 2 3 * \ * 5 * All root-to-leaf paths are: * * [ * "1->2->5", * "1->3" * ] * */ public class BinaryTreePaths { public List<String> binaryTreePaths(TreeNode root) { List<String> list = new ArrayList<>(); getPath(list, root, ""); return list; } private void getPath(List<String> res, TreeNode root, String path) { if (root == null) return; path = path + "->" + root.val; if(root.left == null && root.right == null) res.add(path.substring(2)); getPath(res, root.left, path); getPath(res, root.right, path); } }
相关文章推荐
- 使用Genymotion调试出现错误INSTALL_FAILED_CPU_ABI_INCOMPATI
- TIME_WAIT过多
- http://blog.csdn.net/xyang81/article/details/7292380
- 关于Error: Failed to lookup view "error" in views directory "D:\WebProgram\webBlog\views"的解决方法
- Err http://ppa.launchpad.net trusty/main amd64 Packages 404 Not Found
- HDU 2473 - Junk-Mail Filter ,并查集的删点
- wait和waitpid详解【转】
- linux中waitpid及wait的用法【转】
- 对PyStringObject的认识(Intern机制) http://blog.csdn.net/wangyuquanliuli/article/details/8522302
- django从index访问detail流程
- Ubuntu 14.04 引导修复(Boot Repair)(双系统修复一)
- 自定义dailog注意事项
- Organize Your Train part II-POJ3007模拟
- Organize Your Train part II-POJ3007模拟
- String painter (hdu 2476)
- AI、DI、AO、DO、PI通道代表的意思
- AfxEnableControlContainer()
- RAID简介
- RAID配置
- cvpr读书笔记[3]:traincascade与AdaBoost的opencv实现框架