Skip to content

Commit 80d9e70

Browse files
authored
Create main.cpp
1 parent 5c1a6aa commit 80d9e70

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution{
2+
public:
3+
Node* LCA(Node *root, int n1, int n2)
4+
{
5+
if(root == NULL) return NULL;
6+
7+
while(root != NULL){
8+
if(root -> data < n1 && root -> data < n2){
9+
root = root -> right;
10+
}
11+
12+
else if(root -> data > n1 && root -> data > n2){
13+
root = root -> left;
14+
}
15+
else return root;
16+
}
17+
}
18+
};

0 commit comments

Comments
 (0)