- # Definition for singly-linked list.# class ListNode(object):# def __init__(self, val=0, next=None):# self.val = val# self.next = next
class Solution(object):def middleNode(self, head):""":type head: Optional[ListNode]:rtype: Optional[ListNode]"""if not head or not head.next:# 若链表不存在或只有一个节点时,返回headreturnheadfast, slow = head, headwhile fast and fast.next:fast = fast.next.nextslow = slow.nextreturn slow
大家好,这里是Good Note,关注 公主号:Goodnote,本文详细介绍乐观锁的两种实现方式:版本号机制和CAS(Compare And Swap)。 文章目录 MySQL 内置的并发控制机制MVCC(多版本并发控制&am…