update project structure
This commit is contained in:
25
leetcode_py/21.py
Normal file
25
leetcode_py/21.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# 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 Solution:
|
||||
def mergeTwoLists(self, list1: ListNode, list2: ListNode):
|
||||
prehead = ListNode(-1)
|
||||
prev = prehead
|
||||
|
||||
while list1 and list2:
|
||||
if list1.val <= list2.val:
|
||||
prev.next = list1
|
||||
list1 = list1.next
|
||||
else:
|
||||
prev.next = list2
|
||||
list2 = list2.next
|
||||
prev = prev.next
|
||||
|
||||
return prehead.next
|
||||
Reference in New Issue
Block a user