慢慢练脑子
1. 来源:
题: leetcode
2. 解法:
2.1 递归
class Solution {
public List<Integer> postorderTraversal(TreeNode root) {
List<Integer> result = new ArrayList<>();
helper(result, root);
return result;
}
private void helper(List<Integer> result, TreeNode root) {
if(root == null) {
return;
}
helper(result, root.left);
helper(result, root.right);
result.add(root.val);
}
}
2.1 非递归
网友评论