Skip to content

Implementation Refactoring: Rename Variable/Method, Decompose Conditional, Introduce Explaining Variable #4146

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

Merged
merged 5 commits into from
Apr 14, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor (CheckTreeIsSymmetric): decompose conditional
  • Loading branch information
ishhan committed Apr 6, 2023
commit 6aeb9626084d4245b8018c8b43d7b32ea2456d0c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ private static boolean isSymmetric(Node leftSubtreeRoot, Node rightSubtreRoot) {
return true;
}

if (leftSubtreeRoot == null || rightSubtreRoot == null || leftSubtreeRoot.data != rightSubtreRoot.data) {
if (isInvalidSubtree(leftSubtreeRoot, rightSubtreRoot)) {
return false;
}

return isSymmetric(leftSubtreeRoot.right, rightSubtreRoot.left) && isSymmetric(leftSubtreeRoot.left, rightSubtreRoot.right);
}

private static boolean isInvalidSubtree(Node leftSubtreeRoot, Node rightSubtreeRoot) {
return leftSubtreeRoot == null || rightSubtreeRoot == null || leftSubtreeRoot.data != rightSubtreeRoot.data;
}
}