102. Binary Tree Level Order Traversal

Average value by level in a tree

/**
 * 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> levelOrder(TreeNode root) {
        List> res=new LinkedList<>();
        if(root==null) return res;
        Queue queue=new LinkedList<>();
        queue.offer(root);
        while(!queue.isEmpty()){
            int size=queue.size();
            List list=new LinkedList<>();
            for(int i=0;i

你可能感兴趣的:(102. Binary Tree Level Order Traversal)