Skip to content

Fix some code smell #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/ctci/treesandgraphs/CheckBalanced.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static int checkHeightAndBalance(TreeNode node) {
int leftHeight = checkHeightAndBalance(node.left);
int rightHeight = checkHeightAndBalance(node.right);

if (leftHeight == Integer.MIN_VALUE || rightHeight == Integer.MIN_VALUE || !(leftHeight - rightHeight <= 1)) {
if (leftHeight == Integer.MIN_VALUE || rightHeight == Integer.MIN_VALUE || (leftHeight - rightHeight > 1)) {
return Integer.MIN_VALUE;
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/ctci/treesandgraphs/CheckSubtree.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ private static boolean isT2SubtreeOfT1(TreeNode t1, TreeNode t2) {
return true;
}

if (t1.val == t2.val) {
if (matchTree(t1, t2)) {
if (t1.val == t2.val && matchTree(t1, t2)) {
return true;
}
}
return isT2SubtreeOfT1(t1.left, t2) || isT2SubtreeOfT1(t1.right, t2);
}
Expand Down