MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / lca

Method lca

CPP/Trees/LowestCommonAncestor.cpp:18–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16{
17 public:
18 Node* lca(Node* root ,int n1 ,int n2 )
19 {
20 if(root == NULL || root->data == n1 || root->data == n2) {
21 return root;
22 }
23
24 Node* left = lca(root->left, n1, n2);
25 Node* right = lca(root->right, n1, n2);
26
27 if(left != NULL && right != NULL) {
28 return root;
29 } else if (left != NULL) {
30 return left;
31 } else {
32 return right;
33 }
34 }
35};

Callers

nothing calls this directly

Calls 1

lcaFunction · 0.85

Tested by

no test coverage detected