Skip to content

Commit

Permalink
feat: add solutions to lc problem: No.0146 (#3909)
Browse files Browse the repository at this point in the history
No.0146.LRU Cache
  • Loading branch information
yanglbme authored Dec 31, 2024
1 parent a336f65 commit 398146b
Show file tree
Hide file tree
Showing 14 changed files with 925 additions and 610 deletions.
12 changes: 2 additions & 10 deletions solution/0000-0099/0023.Merge k Sorted Lists/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,7 @@ func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1];

function mergeKLists(lists: Array<ListNode | null>): ListNode | null {
const pq = new MinPriorityQueue({ priority: (node: ListNode) => node.val });
for (const head of lists) {
if (head) {
pq.enqueue(head);
}
}
lists.filter(head => head).forEach(head => pq.enqueue(head));
const dummy: ListNode = new ListNode();
let cur: ListNode = dummy;
while (!pq.isEmpty()) {
Expand Down Expand Up @@ -318,11 +314,7 @@ impl Solution {
*/
var mergeKLists = function (lists) {
const pq = new MinPriorityQueue({ priority: node => node.val });
for (const head of lists) {
if (head) {
pq.enqueue(head);
}
}
lists.filter(head => head).forEach(head => pq.enqueue(head));
const dummy = new ListNode();
let cur = dummy;
while (!pq.isEmpty()) {
Expand Down
12 changes: 2 additions & 10 deletions solution/0000-0099/0023.Merge k Sorted Lists/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,7 @@ func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1];

function mergeKLists(lists: Array<ListNode | null>): ListNode | null {
const pq = new MinPriorityQueue({ priority: (node: ListNode) => node.val });
for (const head of lists) {
if (head) {
pq.enqueue(head);
}
}
lists.filter(head => head).forEach(head => pq.enqueue(head));
const dummy: ListNode = new ListNode();
let cur: ListNode = dummy;
while (!pq.isEmpty()) {
Expand Down Expand Up @@ -319,11 +315,7 @@ impl Solution {
*/
var mergeKLists = function (lists) {
const pq = new MinPriorityQueue({ priority: node => node.val });
for (const head of lists) {
if (head) {
pq.enqueue(head);
}
}
lists.filter(head => head).forEach(head => pq.enqueue(head));
const dummy = new ListNode();
let cur = dummy;
while (!pq.isEmpty()) {
Expand Down
6 changes: 1 addition & 5 deletions solution/0000-0099/0023.Merge k Sorted Lists/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
*/
var mergeKLists = function (lists) {
const pq = new MinPriorityQueue({ priority: node => node.val });
for (const head of lists) {
if (head) {
pq.enqueue(head);
}
}
lists.filter(head => head).forEach(head => pq.enqueue(head));
const dummy = new ListNode();
let cur = dummy;
while (!pq.isEmpty()) {
Expand Down
6 changes: 1 addition & 5 deletions solution/0000-0099/0023.Merge k Sorted Lists/Solution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@

function mergeKLists(lists: Array<ListNode | null>): ListNode | null {
const pq = new MinPriorityQueue({ priority: (node: ListNode) => node.val });
for (const head of lists) {
if (head) {
pq.enqueue(head);
}
}
lists.filter(head => head).forEach(head => pq.enqueue(head));
const dummy: ListNode = new ListNode();
let cur: ListNode = dummy;
while (!pq.isEmpty()) {
Expand Down
Loading

0 comments on commit 398146b

Please sign in to comment.