标签:color code 二叉树 desc des integer treenode port this
import java.util.ArrayList; /* public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public class Solution { ArrayList<ArrayList<Integer> > Print(TreeNode pRoot) { ArrayList<ArrayList<Integer>> list = new ArrayList<>(); depth(pRoot, 1, list); return list; } public void depth(TreeNode node, int depth, ArrayList<ArrayList<Integer>> list) { if(node == null) return; if(depth > list.size()) list.add(new ArrayList<Integer>()); list.get(depth-1).add(node.val); depth(node.left, depth + 1, list); depth(node.right, depth + 1, list); } }
标签:color code 二叉树 desc des integer treenode port this
原文地址:https://www.cnblogs.com/yihangZhou/p/10518247.html