257:二叉树的所有路径(未完成)

This commit is contained in:
huangge1199 2021-07-23 13:52:31 +08:00
parent 7e340e2f4e
commit e2c1b69106
2 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,65 @@
//给定一个二叉树返回所有从根节点到叶子节点的路径
//
// 说明: 叶子节点是指没有子节点的节点
//
// 示例:
//
// 输入:
//
// 1
// / \
//2 3
// \
// 5
//
//输出: ["1->2->5", "1->3"]
//
//解释: 所有根节点到叶子节点的路径为: 1->2->5, 1->3
// Related Topics 深度优先搜索 字符串 二叉树
// 👍 540 👎 0
package leetcode.editor.cn;
import com.code.leet.entiy.TreeNode;
import java.util.ArrayList;
import java.util.List;
//257:二叉树的所有路径
public class BinaryTreePaths{
public static void main(String[] args) {
//测试代码
Solution solution = new BinaryTreePaths().new Solution();
}
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public List<String> binaryTreePaths(TreeNode root) {
if(root==null){
return null;
}
List<String> list = new ArrayList<>();
if(root.left!=null){}
return list;
}
}
//leetcode submit region end(Prohibit modification and deletion)
}

View File

@ -0,0 +1,18 @@
<p>给定一个二叉树,返回所有从根节点到叶子节点的路径。</p>
<p><strong>说明:</strong>&nbsp;叶子节点是指没有子节点的节点。</p>
<p><strong>示例:</strong></p>
<pre><strong>输入:</strong>
1
/ \
2 3
\
5
<strong>输出:</strong> [&quot;1-&gt;2-&gt;5&quot;, &quot;1-&gt;3&quot;]
<strong>解释:</strong> 所有根节点到叶子节点的路径为: 1-&gt;2-&gt;5, 1-&gt;3</pre>
<div><div>Related Topics</div><div><li></li><li>深度优先搜索</li><li>字符串</li><li>二叉树</li></div></div>\n<div><li>👍 540</li><li>👎 0</li></div>