Jan 142021
 

链表,这个我也是第一次碰到,知道他和列表的区别。就借助这个练习来了解。

https://leetcode.com/problems/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, l1: ListNode, l2: ListNode) -> ListNode:


        if l1 is None:
            return l2
        if l2 is None:
            return l1
        if l1.val < l2.val:
            l1.next = self.mergeTwoLists(l1.next, l2)
            return l1
        else:
            l2.next = self.mergeTwoLists(l1, l2.next)
            return l2

慢慢再理解。

  2 Responses to “Leetcode python 07:Merge Two Sorted Lists”

  1. 陈老师好,最近学校要求我们学习 openstack 相关内容,百度搜索发现大家都用的您的 devstack 的国内 mirror 源,但是最近我发现这个网站好像被屏蔽了,想问一下这个网站啥时候可以正常使用

  2. 陈老师好,最近学校要求我们学习 openstack 相关内容,百度搜索发现大家都用的您的 devstack 的国内 mirror 源,但是最近我发现这个网站好像被屏蔽了,所以想问一下这个网站啥时候可以正常使用

 Leave a Reply

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.