摘要:
深度优先搜索 class Solution { public int sumNumbers(TreeNode root) { List<String> list = convertStr(root); int sum = 0; /** * Integer.parseInt()将字符串转为整型 */ 阅读全文
posted @ 2021-12-25 23:54
振袖秋枫问红叶
阅读(29)
评论(0)
推荐(0)
摘要:
深度优先搜索 class Solution { List<List<Integer>> list = new LinkedList<>(); public List<List<Integer>> pathSum(TreeNode root, int targetSum) { dfs(root, ne 阅读全文
posted @ 2021-12-25 22:49
振袖秋枫问红叶
阅读(30)
评论(0)
推荐(0)
摘要:
深度优先搜索 class Solution { List<String> list = new LinkedList<>(); public List<String> binaryTreePaths(TreeNode root) { if (root == null){ return list; } 阅读全文
posted @ 2021-12-25 22:13
振袖秋枫问红叶
阅读(35)
评论(0)
推荐(0)
摘要:
深度优先搜索 class Solution { public int sumOfLeftLeaves(TreeNode root) { if (root == null){ return 0; } int sum = 0; /** * 如果根节点有左孩子,且左孩子是叶子节点时,记录其值 */ if 阅读全文
posted @ 2021-12-25 21:27
振袖秋枫问红叶
阅读(12)
评论(0)
推荐(0)
摘要:
深度优先搜索 class Solution { public int countNodes(TreeNode root) { if (root == null){ return 0; } return countNodes(root.left) + countNodes(root.right) + 阅读全文
posted @ 2021-12-25 20:16
振袖秋枫问红叶
阅读(28)
评论(0)
推荐(0)
摘要:
深度优先搜索(前序遍历) class Solution { public boolean isBalanced(TreeNode root) { if (root == null){ return true; } /** * 自顶向下 * 除了判断左右子树是否是平衡二叉树以外,还要判断左右子树的高度 阅读全文
posted @ 2021-12-25 18:03
振袖秋枫问红叶
阅读(40)
评论(0)
推荐(0)