My JavaScript Solution


  • 0
    S
    var levelOrderBottom = function(root) {
        if(root === null) return [];
    	var res = [[root.val]];
    	var leval = 1;
        function traversal(root,leval){
        	var temp = [];
        	if(root === null) return root;
        	if(root.left!==null){
        		temp.push(root.left.val)
        	}
    		if(root.right!==null){
        		temp.push(root.right.val)
        	}
        	if(temp.length!==0){
        		if(res[leval]=== undefined){
        			res.push(temp)
        		}else{
        			res[leval]=res[leval].concat(temp);
        		}
        	}
        	traversal(root.left,leval+1);
        	traversal(root.right,leval+1);
        }
        traversal(root,leval);
        return res.reverse();
    };
    

Log in to reply
 

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