标签:evel etc turn ini blog size treenode arraylist new
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public List<List<Integer>> levelOrder(TreeNode root) { List<List<Integer>> iListList= new ArrayList<List<Integer>>(); int depth=0; exploreTreeNode(root,iListList,depth ); return iListList; } public void exploreTreeNode(TreeNode root, List<List<Integer>> iListList, int depth){ if(root==null) return; if( depth >= iListList.size() ){ List<Integer> iList = new ArrayList<Integer>(); iListList.add(depth, iList); iList.add(root.val); } else{ iListList.get(depth).add(root.val); } if(null!=root.left){ exploreTreeNode(root.left, iListList , depth+1); } if(null!=root.right){ exploreTreeNode(root.right, iListList , depth+1); } } }
标签:evel etc turn ini blog size treenode arraylist new
原文地址:http://www.cnblogs.com/youge-OneSQL/p/6412888.html