leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0235.cpp (431B)


0 class Solution { 1 public: 2 TreeNode *lowestCommonAncestor(TreeNode *root, TreeNode *p, TreeNode *q) { 3 TreeNode *tmp = root; 4 while (true) { 5 if (root->val > p->val && root->val > q->val) 6 root = root->left; 7 else if (root->val < p->val && root->val < q->val) 8 root = root->right; 9 else 10 break; 11 } 12 return root; 13 } 14 };