using System; using System.Collections.Generic; /* public class TreeNode { public int val; public TreeNode left; public TreeNode right; public TreeNode (int x) { val = x; } } */ class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param root TreeNode类 * @return int整型二维数组 */ public List<List<int>> levelOrder (TreeNode root) { Queue<TreeNode> que = new Queue<TreeNode>(); List<List<int>> bigList = new List<List<int>>(); if(root == null) return bigList; que.Enqueue(root); while(que.Count != 0){ List<int> smallList = new List<int>(); for(int len = que.Count; len > 0; len--){ TreeNode cur = que.Dequeue(); smallList.Add(cur.val); if(cur.left != null)que.Enqueue(cur.left); if(cur.right != null)que.Enqueue(cur.right); } bigList.Add(smallList); } return bigList; } }