update 21
This commit is contained in:
parent
57ea9b4bb5
commit
b64e6c10d6
@ -1,13 +1,23 @@
|
||||
# Merge Two Sorted Lists
|
||||
|
||||
|
||||
# Definition for singly-linked list
|
||||
# class ListNode:
|
||||
# def __init__(self, val = 0, next = None):
|
||||
# self.val = val
|
||||
# self.next = next
|
||||
class ListNode:
|
||||
def __init__(self, val=0, next=None):
|
||||
self.val = val
|
||||
self.next = next
|
||||
|
||||
|
||||
class Solution:
|
||||
def mergeTwoLists(self, list1: list, list2: list):
|
||||
new_list = list1 + list2
|
||||
def mergeTwoLists(self, list1: ListNode, list2: ListNode):
|
||||
new_list1 = []
|
||||
while list1.next is not None:
|
||||
new_list1.append(list1.val)
|
||||
list1 = list1.next
|
||||
new_list2 = []
|
||||
while list2.next is not None:
|
||||
new_list2.append(list2.val)
|
||||
list2 = list2.next
|
||||
|
||||
new_list = new_list1 + new_list2
|
||||
return new_list.sort()
|
||||
|
Loading…
x
Reference in New Issue
Block a user