コード例 #1
0
        public static int DistanceBetweenNodes(this BSTNode root, int nodeVal1, int nodeVal2)
        {
            if (root is null)
            {
                return(0);
            }
            var lca = root.LCA(nodeVal1, nodeVal2);

            if (lca != null)
            {
                return(lca.Distance(nodeVal1) + lca.Distance(nodeVal2));
            }
            return(-1);
        }