摘要:
快慢指针: class Solution: def hasCycle(self, head: Optional[ListNode]) -> bool: # 如果链表为空或者只有一个节点,肯定不存在环 if not head or not head.next: return False # 初始化慢指 阅读全文
摘要:
自己写的: from typing import List class Solution: def singleNumber(self, nums: List[int]) -> int: # 创建一个字典用于存储数字出现的次数 save_dict = dict() # 遍历输入列表 for i in 阅读全文
摘要:
暴力解法,最后内存爆了 class Solution: def maxProfit(self, prices): n=len(prices) if n==1: return 0 if n>1000: return 3 profit = [] for i in range(n): cur=i+1 wh 阅读全文