标签:for code node 二叉搜索树 int val roo struct treenode
1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */ 10 class Solution 11 { 12 public: 13 TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) 14 { 15 if(p == root || q == root || !root) return root; 16 17 TreeNode* a = lowestCommonAncestor(root->left,p,q); 18 TreeNode* b = lowestCommonAncestor(root->right,p,q); 19 if(!a && b) return b; 20 else if(a && !b) return a; 21 else if(a && b) return root; 22 else return NULL; 23 } 24 };
标签:for code node 二叉搜索树 int val roo struct treenode
原文地址:https://www.cnblogs.com/yuhong1103/p/12686632.html