diff --git a/src/main/java/com/thealgorithms/compression/LZ78.java b/src/main/java/com/thealgorithms/compression/LZ78.java index 904c379cc2a2..564afc0d49ed 100644 --- a/src/main/java/com/thealgorithms/compression/LZ78.java +++ b/src/main/java/com/thealgorithms/compression/LZ78.java @@ -4,7 +4,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - +import java.util.objects; /** * An implementation of the Lempel-Ziv 78 (LZ78) compression algorithm. *

@@ -97,12 +97,13 @@ public static List compress(String text) { } // Handle remaining phrase at end of input - if (currentNode != root) { + if (!currentNode.equals(root)) { compressedOutput.add(new Token(lastMatchedIndex, END_OF_STREAM)); } return compressedOutput; - } +} + /** * Decompresses a list of LZ78 tokens back into the original string.