Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Logic:We will traverse the tree as the normal binary tree but leaf nodes left's right will point to the same leaf node and leaf nodes right's left
- will point to the same leaf node,so just return 1 for the leaf node.
- */
- int findTreeHeight(Node* root){
- if(!root) return 0;
- if(root->left && root->left->right==root && root->right && root->right->left==root) return 1;
- return max(findTreeHeight(root->left),findTreeHeight(root->right))+1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement