8000 23rd problem · Adtrex/LeetcodeJs@a3501d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit a3501d0

Browse files
committed
23rd problem
1 parent 79972d7 commit a3501d0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

23. Merge k Sorted Lists.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var mergeKLists = function(lists) {
2+
let a = []
3+
for(let i = 0 ; i < lists.length ; i++){
4+
let k = lists[i]
5+
while(k != null){
6+
a.push(k.val)
7+
k = k.next
8+
}
9+
}
10+
a.sort(function(a,b){return a-b})
11+
let m = new ListNode(0)
12+
let ans = m
13+
for(let j = 0 ; j< a.length ;j++){
14+
let n = new ListNode(a[j])
15+
m.next = n
16+
m = m.next
17+
}
18+
return ans.next
19+
};

0 commit comments

Comments
 (0)
0