I keep getting the initialized value of max as my output for some reason
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
void maxi(struct TreeNode* A,int t,int k){
if(A->left==NULL&&A->right==NULL&&t>k) k=t;
if(A->left!=NULL) maxi(A->left,t+1,k);
if(A->right!=NULL) maxi(A->right,t+1,k);
}
int Solution::maxDepth(TreeNode* A) {
int l=0;
maxi(A,1,l);
return l;
}
The function keeps outputting initialized value of l. In this case 0.
Aucun commentaire:
Enregistrer un commentaire