Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2254ccc

Browse files
authored
Merge pull requestneetcode-gh#1417 from MHamiid/patch-6
Fix 146-Lru-Cache.cpp removed nodes deallocation
2 parents4e9bb36 +b0cfbaa commit2254ccc

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

‎cpp/146-Lru-Cache.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class LRUCache {
4747
voidput(int key,int value) {
4848
if (cache.find(key) != cache.end()) {
4949
remove(cache[key]);
50+
51+
// Free allocated memory for the removed node
52+
delete cache[key];
5053
}
5154
cache[key] =newNode(key, value);
5255
insert(cache[key]);
@@ -56,6 +59,9 @@ class LRUCache {
5659
Node* lru = left->next;
5760
remove(lru);
5861
cache.erase(lru->k);
62+
63+
// Free allocated memory for the removed node
64+
delete lru;
5965
}
6066
}
6167
private:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp