minCommonAncestor<T extends TreeNode<T> > static method
T?
minCommonAncestor<T extends TreeNode<T> >(
- T a,
- T b
返回 节点 a,b的最小公共祖先
Implementation
static T? minCommonAncestor<T extends TreeNode<T>>(T a, T b) {
if (a == b) return a;
var aNodes = a.ancestors();
var bNodes = b.ancestors();
T? c;
a = aNodes.removeLast();
b = bNodes.removeLast();
while (a == b) {
c = a;
a = aNodes.removeLast();
b = bNodes.removeLast();
}
return c;
}