diff --git a/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMap.java b/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMap.java index 3225c437..b583a71e 100644 --- a/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMap.java +++ b/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMap.java @@ -89,7 +89,9 @@ public class HashMap { public void delete(int key) { if (!isEmpty()) { if (first.getKey() == key) { - first = null; + Node next = first.next; + first.next = null; // help GC + first = next; } else { delete(first, key); }