| https://leetcode.com/problems/merge-two-sorted-lists/description/ | Easy |
|---|
class Solution {
fun mergeTwoLists(list1: ListNode?, list2: ListNode?): ListNode? {
var a = list1
var b = list2
val dummy = ListNode(0)
var t = dummy
while (a != null && b != null) {
if (a.`val` <= b.`val`) {
t.next = a
a = a.next
} else {
t.next = b
b = b.next
}
t = t.next!!
}
t.next = a ?: b
return dummy.next
}
}