[lintcode] - 391 Number of Airplanes in the Sky
来源:互联网 发布:单片机小精灵手机版 编辑:程序博客网 时间:2024/06/14 07:24
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); }}
0 0
- lintcode:Number of Airplanes in the Sky
- [LintCode]Number of Airplanes in the Sky
- [lintcode] - 391 Number of Airplanes in the Sky
- LintCode --number-of-airplanes-in-the-sky(数飞机)
- LintCode Number of Airplanes in the Sky(Java)
- lintcdoe: Number of Airplanes in the Sky
- 391.Number of Airplanes in the Sky-数飞机(中等题)
- PIE IN THE SKY
- The Scar of the Sky
- [Lintcode]Number of Islands
- Sky number
- The sky in my heart is raining...
- count the number of "1" in the binary figure
- [Lintcode]Count of Smaller Number
- LintCode 433: Number of Islands
- lintcode: Count of Smaller Number
- LintCode Maximum Number in Mountain
- Invalid update: invalid number of rows in section 0. The number of rows contained in an ....
- 阅读《Android 从入门到精通》(18)——拖动条
- hdu 5612 /BC 69C Baby Ming and Matrix games
- Leetcode tree题型总结
- 解决Missing forwarded port for XXX,Unable to get view server version from deviceXX
- jQuery学习之旅 7 区别this和$(this)
- [lintcode] - 391 Number of Airplanes in the Sky
- 世界各国2015-2020GDP排名
- opencv处理
- 8 Maven-聚合
- Windows MySQL(zip版本),启动不了,因为缺少data文件。(双系统修复三)
- Google Earth安装不显示问题
- 安卓--第八天--蓝牙框架的整体分析
- Real-Time Hair Simulating And Rendering
- jna调用c 的dll(包含回调函数)