category-wise-problems

contains category wise problems(data structures, competitive) of popular platforms.

View the Project on GitHub mayankdutta/category-wise-problems

236. Lowest Common Ancestor of a Binary Tree

Code ```cpp class Solution { public: TreeNode* fun(TreeNode *root, TreeNode *p, TreeNode *q) { if (root == p or root == q or root == nullptr) return root; auto left = fun(root -> left, p, q); auto right = fun(root -> right, p, q); if (left && right) return root; return (left != nullptr) ? left : right; } TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { return fun(root, p, q); } }; ```