2025年11月14日

摘要: 链接:155. 最小栈 - 力扣(LeetCode) 在类里面维护一个最小栈,用来记录栈顶到栈底的最小值 1 class MinStack(object): 2 3 def __init__(self): 4 self.stack = [] 5 self.min_stack = [] 6 7 def 阅读全文
posted @ 2025-11-14 22:46 Annetree 阅读(3) 评论(0) 推荐(0)
 
摘要: 链接:20. 有效的括号 - 力扣(LeetCode) python中list就可以直接当栈用 1 class Solution(object): 2 def isValid(self, s): 3 """ 4 :type s: str 5 :rtype: bool 6 """ 7 length = 阅读全文
posted @ 2025-11-14 22:19 Annetree 阅读(3) 评论(0) 推荐(0)
 
摘要: 链接:240. 搜索二维矩阵 II - 力扣(LeetCode) 从右上角开始搜索,即(x,y)从(0,n-1开始),如果[x,y]值小于目标值,x+=1,如果大于目标值,y-=1 1 class Solution(object): 2 def searchMatrix(self, matrix, 阅读全文
posted @ 2025-11-14 14:48 Annetree 阅读(3) 评论(0) 推荐(0)