Esempio n. 1
0
        public void ShouldFind_LCA_AtRoot()
        {
            var nodes = new int?[] { 6, 2, 8, 0, 4, 7, 9, null, null, 3, 5 };
            var tree  = new TreeNode(nodes);

            var p = new TreeNode(2);
            var q = new TreeNode(8);

            var lca = LowestCommonAncestor.FindLowestCommonAncestor(tree, p, q);

            Assert.AreEqual(6, lca.val);
        }
Esempio n. 2
0
        public void ShouldFind_LCA_AtLeft_FirstAndSecondLevel()
        {
            var nodes = new int?[] { 6, 2, 8, 0, 4, 7, 9, null, null, 3, 5 };
            var tree  = new TreeNode(nodes);

            var p = new TreeNode(0);
            var q = new TreeNode(5);

            var lca = LowestCommonAncestor.FindLowestCommonAncestor(tree, p, q);

            Assert.AreEqual(2, lca.val);
        }