Skip to content

Commit

Permalink
Time: 188 ms (36.24%), Space: 94.3 MB (63.41%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipendra-Raghav committed Apr 19, 2023
1 parent 944754a commit cbb2a12
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public:
int mx=0;
int solve(TreeNode* root,bool flag)
{
if(root==NULL)return 0;
int left=1+solve(root->left,true);
int right=1+solve(root->right,false);
mx=max(mx,max(left,right));
return flag==true?right:left;

}
int longestZigZag(TreeNode* root) {
solve(root,true);
return mx-1;
}
};

0 comments on commit cbb2a12

Please sign in to comment.