You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Description: You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it.
4
+
* Author: Hasibul Islam
5
+
* Date: 10/04/2023
6
+
*/
7
+
8
+
/**
9
+
* Definition for singly-linked list.
10
+
* function ListNode(val, next) {
11
+
* this.val = (val===undefined ? 0 : val)
12
+
* this.next = (next===undefined ? null : next)
13
+
* }
14
+
*/
15
+
/**
16
+
* @param {ListNode[]} lists
17
+
* @return {ListNode}
18
+
*/
19
+
constmergeKLists=(lists)=>{
20
+
letarr=[];
21
+
22
+
//flatten
23
+
functionaddNode(node){
24
+
if(node!=null){
25
+
arr.push(node);
26
+
addNode(node.next);
27
+
node.next=null;//prevent leetcode Javascript heap out of memory
0 commit comments