Why wrong? [Input: {0,0,0,0,#,#,0,#,#,#,0} Output: 5 Expected: 4 ]


  • 1
    Y

    Why wrong?

    Submission Result: Wrong Answer Runtime Error Message: Last executed input:
    Input: {0,0,0,0,#,#,0,#,#,#,0} Output: 5 Expected: 4

    class Solution {
    public:
    int maxDepth(TreeNode *root) {
    static int ret = 1;
    static int max = 1;
    if (root == NULL) {
    return 0;
    }
    if (root->left != NULL) {
    ret++;
    maxDepth(root->left);
    ret--;
    }
    if (root->right != NULL) {
    ret++;
    maxDepth(root->right);
    ret--;
    }
    if((root->left == NULL) && (root->right == NULL)) {
    if(max < ret) {
    max = ret;
    }
    }
    return max;
    }
    };


Log in to reply
 

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