4 ms·
I've used zip before to find an LCA: def lca(a,b) a.ancestors.zip(b.ancestors).take_while { |a,b| a == b }.last end
by charliesome 15y ago
I've used zip before to find an LCA:
def lca(a,b)
a.ancestors.zip(b.ancestors).take_while { |a,b| a == b }.last
end