From 90da073f2f36de08bbf1caccb433b771ea02bb9e Mon Sep 17 00:00:00 2001 From: wasim0315 <50516723+wasim0315@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:08:40 +0530 Subject: [PATCH] Create solu.cpp --- .../Tree : Height of a Binary Tree/solu.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 DataStructures/Trees/Tree : Height of a Binary Tree/solu.cpp diff --git a/DataStructures/Trees/Tree : Height of a Binary Tree/solu.cpp b/DataStructures/Trees/Tree : Height of a Binary Tree/solu.cpp new file mode 100644 index 0000000..0413479 --- /dev/null +++ b/DataStructures/Trees/Tree : Height of a Binary Tree/solu.cpp @@ -0,0 +1,20 @@ + +/*The tree node has data, left child and right child +class Node { + int data; + Node* left; + Node* right; +}; + +*/ + int height(Node* root) { + // Write your code here. + if(root == NULL){ + return -1; + } + int left = height(root->left); + int right = height(root->right); + int max = left > right ? left : right; + return max+1; + } +