2025-06-04 lc59. Spiral Matrix II
date: 2025-06-04 name: aliases: tags: leetcode python 语法 date_last_edit: 2025-06-04 04:47 — 2025-06-04
date: 2025-06-04 name: aliases: tags:
— creation date: 2025-06-04 00:31 — modification date: 星期三 4日 六月 2025 00:31:47
209. Minimum Size Subarray Sum
之前写过, 但是没写过一遍这样的思路, 感觉重新做已经有点忘记了, OK, 现在这样新写一遍吧, 我新看了一遍题目, 感觉是滑动窗口的最简单版本的题目
直接写吧
class Solution:
def minSubArrayLen(self, target: int, nums: List[int]) -> int:
left = 0
right = 0
win = []
ans = 0
n = len(nums)
while right < n:
混乱的写法, 突然发现其实不需要这个 win 来存实际的数组, 我只要知道这个 sum 值就行了, 于是
class Solution:
def minSubArrayLen(self, target: int, nums: List[int]) -> int:
left = 0
right = 0
# win = []
ans = 0
n = len(nums)
while right < n:
if sum
# win.append(nums[right])
right += 1
我改成了, 一个 ` sum_win` 的值 finally 写成了这样错了,
class Solution:
def minSubArrayLen(self, target: int, nums: List[int]) -> int:
left = 0
right = 0
sum_win = 0
ans = math.inf
n = len(nums)
while right < n:
while sum_win >= target:# 不应该用if, 应该用while
ans = min(ans,right - left)
sum_win -= nums[left]
left += 1
sum_win += nums[right]
right += 1
return ans if ans != math.inf else 0
问了 gpt, 改正很简单, 就是放到前面去
class Solution:
def minSubArrayLen(self, target: int, nums: List[int]) -> int:
left = 0
right = 0
sum_win = 0
ans = math.inf
n = len(nums)
while right < n:
sum_win += nums[right]
right += 1
while sum_win >= target:# 不应该用if, 应该用while
ans = min(ans,right - left)
sum_win -= nums[left]
left += 1
return ans if ans != math.inf else 0
思考: 为什么会出现这个逻辑上的错误, 改成正确的代码其实很简单,但是我其实想知道的是如何从直觉的角度去修正这个问题。
滑窗三部曲:扩、判、缩。
date: 2025-06-04 name: aliases: tags: leetcode python 语法 date_last_edit: 2025-06-04 04:47 — 2025-06-04
date: 2025-06-03 name: aliases: tags: leetcode python 双指针 date_last_edit: 2025-06-03 18:37 — 2025-06-03
date: 2025-06-03 name: aliases: tags: leetcode python BinarySearch date_last_edit: 2025-06-03 16:46 — 2025-06-03
date: 2025-06-04 name: aliases: tags: leetcode python 双指针 date_last_edit: 2025-06-04 00:31 — 2025-06-04
使用GPT辅助对话的思考
使用 GPT refine 了文章
好像写成一个的线代的内容了, 有很多未完待续的内容
Using LLMs to refine context through chaotic thinking, but I think GPT-4.5 (2025-04-22) is quite good.
The article contains mistakes and misunderstandings, as it is a record of my own incorrect notes rather than a proper summary document.
https://www.youtube.com/watch?v=EWvNQjAaOHw
记录签证准备材料的list
文章翻译, 阅读, 解读MTF曲线, 笔记总结 Preface
A record of some simple ideas.
UCLA online learning how to learn powerful mental tools to help you master tough subjects
虎头蛇尾…
A small concept in discrete mathematics
进度条…(2/8)
The article contains three proofs.
mainly talk about FM&PM in ELEC202 at Lec 7&8