Exemple #1
0
        public void FindTiltTests()
        {
            BinaryTreeTilt obj = new BinaryTreeTilt();

            TreeNode node = new TreeNode(1)
            {
                left = new TreeNode(2)
                {
                },
                right = new TreeNode(3)
                {
                }
            };

            var x = obj.FindTilt(node);//1

            node = new TreeNode(1)
            {
                left = new TreeNode(2)
                {
                }
            };

            x = obj.FindTilt(node);//2
        }
Exemple #2
0
        public void BinaryTreeTilt_WhenNotCompleteBinary_ReturnExpected()
        {
            var helper = new BinaryTreeTilt();
            var root   = new TreeNode
            {
                val  = 4,
                left = new TreeNode
                {
                    val  = 2,
                    left = new TreeNode
                    {
                        val = 3
                    },
                    right = new TreeNode
                    {
                        val = 5
                    }
                },
                right = new TreeNode
                {
                    val  = 9,
                    left = new TreeNode
                    {
                        val = 7
                    }
                }
            };


            var result = helper.FindTilt(root);

            Assert.That(result, Is.EqualTo(15));
        }
Exemple #3
0
        public void BinaryTreeTilt_When2Level_ReturnExpected()
        {
            var helper = new BinaryTreeTilt();
            var root   = new TreeNode
            {
                val  = 1,
                left = new TreeNode
                {
                    val = 2,
                },
                right = new TreeNode
                {
                    val = 3,
                }
            };


            var result = helper.FindTilt(root);

            Assert.That(result, Is.EqualTo(1));
        }