Refactoring (#4146)

This commit is contained in:
Ishan Makadia
2023-04-14 05:34:47 -03:00
committed by GitHub
parent d241fafd64
commit 0c618b5ee8
3 changed files with 26 additions and 22 deletions

View File

@ -47,7 +47,8 @@ public class HamiltonianCycle {
* @returns true if path is found false otherwise
*/
public boolean isPathFound(int vertex) {
if (this.graph[vertex][0] == 1 && this.pathCount == this.V) {
boolean isLastVertexConnectedToStart = this.graph[vertex][0] == 1 && this.pathCount == this.V;
if (isLastVertexConnectedToStart) {
return true;
}

View File

@ -44,10 +44,14 @@ public class CheckTreeIsSymmetric {
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;
}
}