0
点赞
收藏
分享

微信扫一扫

Python金融数据获取工具库之baostock使用详解

解题思路

水题,主要用于后面的链表的归并排序做了该题

AC代码

# 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: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
        res = ListNode()
        temp = res

        while list1 and list2:
            if list1.val < list2.val:
                temp.next = list1
                temp = temp.next
                list1 = list1.next
            else:
                temp.next = list2
                temp = temp.next
                list2 = list2.next  

        temp.next = list1 if list1 else list2
        return res.next
        
举报

相关推荐

0 条评论