[simple JavaScript] Why is this problem marked as hard ?


  • 0
    F

    This problem is the symetrical of binary-tree-preorder-traversal/ , a question marked as "medium"

    in consequence here is a simple solution in JS :

    var postorderTraversal = function(root) {
        var to_visit = [];
        var visited = [];
        to_visit.push(root);
            while(to_visit.length > 0) {
                var current = to_visit.pop();
                if(current !==null) {
                    visited.push(current.val);
                    to_visit.push(current.left);
                    to_visit.push(current.right);
                   
                }
            }
        visited.reverse();
        return visited;
    };

Log in to reply
 

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