Skip to content

Commit 66930f4

Browse files
committed
Simplify implementation.
1 parent ee0a012 commit 66930f4

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

data_structures/source/test/trees/binary_trees/test_height_balanced_binary_tree.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ TEST_F(SetupBinaryTree, EvenOddTreeIsNotBalanced) {
2424
EXPECT_FALSE(height_balanced_binary_tree(root));
2525
}
2626

27+
TEST_F(SetupBinaryTree, EvenOddTree2IsNotBalanced) {
28+
auto root = even_odd_tree2();
29+
EXPECT_FALSE(height_balanced_binary_tree(root));
30+
}
31+
2732
TEST_F(SetupBinaryTree, TwoNodesIsBalanced) {
2833
auto root = new TreeNode<int>(1);
2934
root->right = new TreeNode<int>(2);

data_structures/source/trees/binary_trees/height_balanced_binary_tree.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ int balanced_height(TreeNode<T>* node)
1717
if(!node)
1818
return 0;
1919
const int left_height = balanced_height(node->left);
20-
if(left_height == -1)
21-
return -1;
2220
const int right_height = balanced_height(node->right);
23-
2421
if (std::abs(left_height - right_height) > 1)
2522
return -1;
2623
return 1 + std::max(left_height, right_height);

0 commit comments

Comments
 (0)