国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

leetcode--107. Binary Tree Level Order Traversal II

2019-11-14 12:05:26
字體:
來源:轉載
供稿:網友

Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).

題解

/** * 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) { Queue<TreeNode> queue = new LinkedList<TreeNode>(); List<List<Integer>> ans = new LinkedList<>(); if(root == null) return ans; queue.offer(root); while(!queue.isEmpty()){ int levelNum = queue.size(); List<Integer> tmpList = new LinkedList<>(); for(int i = 0; i < levelNum; ++i){ if(queue.peek().left != null) queue.offer(queue.peek().left); if(queue.peek().right != null) queue.offer(queue.peek().right); tmpList.add(queue.poll().val); } ans.add(0, tmpList); } return ans; }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蒲江县| 乐平市| 西乡县| 宣汉县| 福州市| 平谷区| 澄城县| 弋阳县| 肇源县| 洛南县| 乐清市| 独山县| 漳浦县| 盐亭县| 盘山县| 宁德市| 临泉县| 江永县| 乐昌市| 正安县| 永德县| 得荣县| 年辖:市辖区| 桂林市| 江陵县| 建瓯市| 三门县| 盱眙县| 仁怀市| 长宁区| 海南省| 广元市| 紫云| 垦利县| 武冈市| 柳州市| 龙门县| 兴山县| 元朗区| 桓仁| 芦溪县|