一、题目
1、合并两个数组
class Solution:def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:nums1[m:] = nums2nums1.sort()
2、判断链表中是否有环
class Solution:def hasCycle(self, head: ListNode) -> bool:seen = set()while head:if head in seen:return Trueseen.add(head)head = head.nextreturn False
3、反转链表
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:cur=headpre=Nonewhile cur:nnext = cur.nextcur.next = prepre = curcur = nnextreturn pre
二、问答
1、数组和链表的区别