C++ post-order traverse


  • 0
    F
    int findBLV(TreeNode* node, int &level, TreeNode* parent)
    {
        if(node == NULL) return parent->val;
        int leftLevel = level+1;
        int rightLevel = level+1;
        int leftVal = findBLV(node->left, leftLevel, node);
        int rightVal = findBLV(node->right, rightLevel, node);
    
        if(rightLevel > leftLevel) {
            level = rightLevel;
            return rightVal;
        }
        level = leftLevel;
        return leftVal;
    }
    
    int findBottomLeftValue(TreeNode* root) {
        int level=0;
        return findBLV(root, level, NULL);
    }

Log in to reply
 

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