Advertisement
imashutosh51

Height of spiral tree

Jul 31st, 2022 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. /*
  2.   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
  3.   will point to the same leaf node,so just return 1 for the leaf node.
  4. */
  5. int findTreeHeight(Node* root){
  6.     if(!root) return 0;
  7.     if(root->left && root->left->right==root && root->right && root->right->left==root) return 1;
  8.     return max(findTreeHeight(root->left),findTreeHeight(root->right))+1;
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement