solution


  • 0
    N

    ...
    class Solution {
    public List<List<Integer>> levelOrderBottom(TreeNode root) {

         Queue<TreeNode> q = new LinkedList<TreeNode>();
        List<List<Integer>> levelList = new ArrayList();
        List<Integer> list ;
        if(root == null)
            return levelList;
        q.add(root);
        int nodecount;
        while(!q.isEmpty()){
            nodecount = q.size();
            list = new ArrayList();
        for(int i=0;i<nodecount;i++){
            TreeNode node = q.remove();
            list.add(node.val);
            if(node.left != null)
            q.add(node.left);
            if(node.right != null)
            q.add(node.right);
        
        }
            levelList.add(0,list);            
        }
        
        return levelList;        
        
    }
    

    }
    ...


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.