From 30904f23f502d8e331b23938adc3aecc81eacb42 Mon Sep 17 00:00:00 2001 From: wasim0315 <50516723+wasim0315@users.noreply.github.com> Date: Thu, 1 Oct 2020 12:11:56 +0530 Subject: [PATCH] Create solution.cpp --- .../solution.cpp | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Hacker-Rank/Binary Search Tree : Lowest Common Ancestor/solution.cpp diff --git a/Hacker-Rank/Binary Search Tree : Lowest Common Ancestor/solution.cpp b/Hacker-Rank/Binary Search Tree : Lowest Common Ancestor/solution.cpp new file mode 100644 index 0000000..0fb2fa3 --- /dev/null +++ b/Hacker-Rank/Binary Search Tree : Lowest Common Ancestor/solution.cpp @@ -0,0 +1,29 @@ +//Link for the Question +//www.hackerrank.com/challenges/binary-search-tree-lowest-common-ancestor/submissions + +/*The tree node has data, left child and right child +class Node { + int data; + Node* left; + Node* right; +}; + +*/ + + Node *lca(Node *root, int v1,int v2) { + // Write your code here. + while(true) + { + if(root->data>v1&&root->data>v2) + { + root=root->left; + } + else if(root->datadataright; + } + else + return root; + } + } +