Skip to content

Commit 01c3c83

Browse files
committed
Fix: use Object.equals for camparison in LZ78
1 parent a14e1e3 commit 01c3c83

File tree

1 file changed

+4
-3
lines changed
  • src/main/java/com/thealgorithms/compression

1 file changed

+4
-3
lines changed

src/main/java/com/thealgorithms/compression/LZ78.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.util.HashMap;
55
import java.util.List;
66
import java.util.Map;
7-
7+
import java.util.objects;
88
/**
99
* An implementation of the Lempel-Ziv 78 (LZ78) compression algorithm.
1010
* <p>
@@ -97,12 +97,13 @@ public static List<Token> compress(String text) {
9797
}
9898

9999
// Handle remaining phrase at end of input
100-
if (currentNode != root) {
100+
if (!currentNode.equals(root)) {
101101
compressedOutput.add(new Token(lastMatchedIndex, END_OF_STREAM));
102102
}
103103

104104
return compressedOutput;
105-
}
105+
}
106+
106107

107108
/**
108109
* Decompresses a list of LZ78 tokens back into the original string.

0 commit comments

Comments
 (0)