注意以下几项
1. 输入若为NULL,返回空列表,而不是NULL,题目没有说清楚
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public List<Integer> postorderTraversal(TreeNode root) { if(root==null){ return new ArrayList<Integer>(); } List<Integer> result = new ArrayList<Integer>(); if(root.left!=null){ result.addAll(postorderTraversal(root.left)); } if(root.right != null){ result.addAll(postorderTraversal(root.right)); } result.add(root.val); return result; } }
相关推荐
145.Binary_Tree_Postorder_Traversal二叉树的后序遍历【LeetCode单题讲解系列】
144.Binary_Tree_Preorder_Traversal二叉树的前序遍历【LeetCode单题讲解系列】
javascript js_leetcode题解之145-binary-tree-postorder-traversal.js
java java_leetcode-107-binary-tree-level-order-traversal
java java_leetcode-102-binary-tree-level-order-traversal
js js_leetcode题解之107-binary-tree-level-order-traversal-ii.js
java java_leetcode-114-flatten-binary-tree-to-linked-list
java java_leetcode-105-construct-binary-tree-from-preorder-and-inorde
public void helper(TreeNode root, int level){// 当前层没有 list,新建// 取得当前层的 list迭代pub
python python_leetcode题解之145_Binary_Tree_Postorder_Traversal
94.Binary_Tree_Inorder_Traversal二叉树的中序遍历【LeetCode单题讲解系列】
javascript js_leetcode题解之144-binary-tree-preorder-traversal.js
js js_leetcode题解之102-binary-tree-level-order-traversal.js
js js_leetcode题解之103-binary-tree-zigzag-level-order-traversal.js
python python_leetcode题解之107_Binary_Tree_Level_Order_Traversal_II
示例解题思路最大的深度是左子树或右子树中深度中更大的一个+1,递归的在子树的子树中寻找代码实现Definition for a binary tree node
LeetCode solution. 按层次遍历二叉树 按层次遍历二叉树 按层次遍历二叉树 按层次遍历二叉树 按层次遍历二叉树
java java_leetcode-99-recover-binary-search-tree