标签:lin integer evel roo order treenode oid port def
import java.util.*; /** * 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>> levelOrderBottom(TreeNode root) { List<List<Integer>> wrapList = new LinkedList<List<Integer>>(); levelMaker(wrapList, root, 0); return wrapList; } public void levelMaker(List<List<Integer>> list, TreeNode root, int level) { if (root == null) return; if (level >= list.size()) { list.add(0, new LinkedList<Integer>()); } levelMaker(list, root.left, level + 1); levelMaker(list, root.right, level + 1); list.get(list.size() - level - 1).add(root.val); } }
标签:lin integer evel roo order treenode oid port def
原文地址:https://www.cnblogs.com/wangtinglou/p/9356355.html