Пример #1
0
        public void TestWithNormalTree_TargetPathIncludeRootNode()
        {
            var target = new BinaryTreeMaximumPathSum_124();

            var tree = new TreeNode(-3)
            {
                left = new TreeNode(5) // 路径包括左子节点和根节点
                {
                    left  = new TreeNode(20),
                    right = new TreeNode(-2)
                }
            };

            Assert.Equal(25, target.MaxPathSum(tree));
        }
Пример #2
0
        public void TestWithNormalTree_TargetPathLimitedInLeftNode()
        {
            var target = new BinaryTreeMaximumPathSum_124();

            var tree = new TreeNode(-3)
            {
                left = new TreeNode(-1) // 路径限定在左子节点内部
                {
                    left  = new TreeNode(20),
                    right = new TreeNode(-2)
                }
            };

            Assert.Equal(20, target.MaxPathSum(tree));
        }
Пример #3
0
        public void TestWithNormalTree_TargetPathIncludeLeftRootAndRight()
        {
            var target = new BinaryTreeMaximumPathSum_124();

            var tree = new TreeNode(5)
            {
                left = new TreeNode(5) // 路径包括左子节点,根节点以及右子节点
                {
                    left  = new TreeNode(20),
                    right = new TreeNode(6)
                },
                right = new TreeNode(-2)
            };

            Assert.Equal(31, target.MaxPathSum(tree));
        }