From 01c3c83e1d1201efc6ac5946ac813bbae0c181a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Galv=C3=A3o?= Date: Wed, 26 Nov 2025 20:33:42 -0300 Subject: [PATCH] Fix: use Object.equals for camparison in LZ78 --- src/main/java/com/thealgorithms/compression/LZ78.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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.