随笔分类 - 代码随想录
摘要:LeetCode 122. 买卖股票的最佳时机 II class Solution: def maxProfit(self, prices: List[int]) -> int: res = 0 for i in range(1, len(prices)): res += max(0, prices
阅读全文
摘要:LeetCode 455. 分发饼干 贪心就是干 class Solution: def findContentChildren(self, g: List[int], s: List[int]) -> int: g.sort(reverse = True) s.sort(reverse = Tru
阅读全文
摘要:LeetCode 24. 两两交换链表中的节点 递归思想 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.ne
阅读全文
摘要:LeetCode 203. 移除链表元素 链表基础概念题,也可以用递归做,不过我们把递归的思想放在更能体现它的LeetCode 206.反转链表 # Definition for singly-linked list. # class ListNode: # def __init__(self, v
阅读全文
摘要:LeetCode 209. 长度最小的子数组 子数组是一个连续的,很容易想到滑动窗口 class Solution: def minSubArrayLen(self, target: int, nums: List[int]) -> int: windowSum = 0 left, right =
阅读全文
摘要:LeetCode 704. 二分查找 核心:明白[left, right] 和 [left, right)两种循环不变量 class Solution: def search(self, nums: List[int], target: int) -> int: left, right = 0, l
阅读全文