Esempio n. 1
0
        public void Test5()
        {
            //Given
            var nodeM1 = new TreeNode(-1);

            //When
            var sut = new BinaryTreeMaxPathSum();
            int sum = sut.MaxPathSum(nodeM1);

            //Then
            sum.Should().Be(-1);
        }
Esempio n. 2
0
        public void Test1()
        {
            //Given
            var node2 = new TreeNode(2);
            var node3 = new TreeNode(3);
            var node1 = new TreeNode(1, node2, node3);

            //When
            var sut = new BinaryTreeMaxPathSum();
            int sum = sut.MaxPathSum(node1);

            //Then
            sum.Should().Be(6);
        }
Esempio n. 3
0
        public void Test3()
        {
            // Input: [-10,9,20,null,null,15,7]
            //      -10
            //      / \
            //     9  20
            //    /    \
            //   15     7
            // Output: 42
            var node15  = new TreeNode(15);
            var node9   = new TreeNode(9, node15);
            var node7   = new TreeNode(7);
            var node20  = new TreeNode(20, null, node7);
            var nodeM10 = new TreeNode(-10, node9, node20);

            var sut = new BinaryTreeMaxPathSum();
            int sum = sut.MaxPathSum(nodeM10);

            sum.Should().Be(41);
        }
        void InternalTest(TreeNode root, int expected)
        {
            int actual = BinaryTreeMaxPathSum.MaxPathSum(root);

            Assert.Equal(expected, actual);
        }