标签:bin nod lis root off ++ ret bottom integer
1 class Solution { 2 public List<List<Integer>> levelOrderBottom(TreeNode root) { 3 Queue<TreeNode> queue = new LinkedList<>(); 4 List<List<Integer>> res = new ArrayList<>(); 5 if(root == null) return res; 6 queue.offer(root); 7 int size = queue.size(); 8 List<Integer> list = new ArrayList<>(); 9 while(!queue.isEmpty()) { 10 for(int i = 0; i < size; i++) { 11 TreeNode node = queue.poll(); 12 list.add(node.val); 13 if(node.left != null) { 14 queue.offer(node.left); 15 } 16 if(node.right != null) { 17 queue.offer(node.right); 18 } 19 } 20 size = queue.size(); 21 res.add(0, list); 22 list = new ArrayList<>(); 23 } 24 return res; 25 } 26 }
107. Binary Tree Level Order Traversal II
标签:bin nod lis root off ++ ret bottom integer
原文地址:https://www.cnblogs.com/goPanama/p/9678654.html