当前位置:首页>python>Python版_Leetcode_hot100系列(15)--动态规划

Python版_Leetcode_hot100系列(15)--动态规划

  • 2026-01-26 06:55:55
Python版_Leetcode_hot100系列(15)--动态规划

70.爬楼梯

🎭 题目小剧场

想象你在爬楼梯,每次可以爬1级或2级。要到达第n级台阶,有多少种不同的爬法?就像选择不同的路径到达山顶,每一步的选择都会影响最终的结果!

💡 解题思路

动态规划解法:

  1. 确定状态:dp[i] 表示到达第i级台阶的方法数

  2. 状态转移:dp[i] = dp[i-1] + dp[i-2]

  3. 初始条件:dp[0] = 1, dp[1] = 1

  4. 空间优化:只保留前两个状态

🐍 Python代码实现

class Solution:    def climbStairs(self, n: int) -> int:        """        动态规划解法(空间优化) - 时间复杂度O(n),空间复杂度O(1)        """        if n <= 2:            return n        # dp[i-2] 和 dp[i-1]        prev2, prev1 = 12        for i in range(3, n + 1):            current = prev1 + prev2            prev2, prev1 = prev1, current        return prev1

📊 复杂度分析

  • 时间复杂度:O(n) - 只需要遍历一次

  • 空间复杂度:O(1) - 只使用常数额外空间

🌟 算法精髓

这个算法的巧妙之处在于"状态压缩"。我们不需要存储所有中间结果,只需要保留前两个状态就能计算出当前状态,大大节省了空间。

🎯 小白友好贴士

  • if n <= 2: return n 处理边界情况

  • prev2, prev1 = 1, 2 初始化前两个状态

  • current = prev1 + prev2 计算当前状态

  • prev2, prev1 = prev1, current 更新状态

  • return prev1 返回最终结果

🔍 算法执行过程示例

示例:n = 4初始:prev2 = 1, prev1 = 21步:i = 3  current = prev1 + prev2 = 2 + 1 = 3  prev2, prev1 = prev1, current = 232步:i = 4  current = prev1 + prev2 = 3 + 2 = 5  prev2, prev1 = prev1, current = 35结束:return prev1 = 5 ✅验证:  第1级:[1] → 1种方法  第2级:[1+12] → 2种方法  第3级:[1+1+11+22+1] → 3种方法  第4级:[1+1+1+11+1+21+2+12+1+12+2] → 5种方法

🎯 核心思想总结

  1. 状态定义:明确dp数组的含义

  2. 状态转移:找到递推关系

  3. 初始条件:确定边界值

  4. 空间优化:减少不必要的存储


118.杨辉三角

🎭 题目小剧场

想象你在构建一个数字金字塔,每个数字都是它"肩膀"上两个数字的和。这个美丽的数学图案不仅看起来优雅,还隐藏着组合数学的奥秘!

💡 解题思路

动态规划解法:

  1. 初始化结果列表,第一行是[1]

  2. 从第二行开始,每行的首尾都是1

  3. 中间的数字等于上一行相邻两个数字之和

  4. 逐行构建直到第n行

🐍 Python代码实现

class Solution:    def generate(self, numRows: int) -> List[List[int]]:        """        动态规划解法 - 时间复杂度O(n²),空间复杂度O(n²)        """        if numRows <= 0:            return []        result = []        for row_num in range(numRows):            # 创建当前行            row = [1] * (row_num + 1)            # 计算中间的数字            for j in range(1, row_num):                row[j] = result[row_num - 1][j - 1] + result[row_num - 1][j]            result.append(row)        return result

📊 复杂度分析

  • 时间复杂度:O(n²) - 需要生成n行,每行平均长度为n/2

  • 空间复杂度:O(n²) - 需要存储整个杨辉三角

🌟 算法精髓

这个算法的巧妙之处在于"逐层构建"。我们利用杨辉三角的递推性质,每一行都基于上一行来构建,避免了复杂的组合计算。

🎯 小白友好贴士

  • if numRows <= 0: return [] 处理边界情况

  • row = [1] * (row_num + 1) 创建当前行并初始化为1

  • for j in range(1, row_num) 只计算中间位置

  • row[j] = result[row_num - 1][j - 1] + result[row_num - 1][j] 递推公式

  • result.append(row) 将当前行加入结果

🔍 算法执行过程示例

示例:numRows = 5初始:result = []1行:row_num = 0  row = [1* 1 = [1]  result = [[1]]2行:row_num = 1  row = [1* 2 = [11]  result = [[1], [11]]3行:row_num = 2  row = [1* 3 = [111]  j = 1row[1= result[1][0+ result[1][1= 1 + 1 = 2  row = [121]  result = [[1], [11], [121]]4行:row_num = 3  row = [1* 4 = [1111]  j = 1row[1= result[2][0+ result[2][1= 1 + 2 = 3  j = 2row[2= result[2][1+ result[2][2= 2 + 1 = 3  row = [1331]  result = [[1], [11], [121], [1331]]5行:row_num = 4  row = [1* 5 = [11111]  j = 1row[1= result[3][0+ result[3][1= 1 + 3 = 4  j = 2row[2= result[3][1+ result[3][2= 3 + 3 = 6  j = 3row[3= result[3][2+ result[3][3= 3 + 1 = 4  row = [14641]  result = [[1], [11], [121], [1331], [14641]]结束:return result ✅

🎯 核心思想总结

  1. 递推关系:每个数字等于上方两个数字之和

  2. 边界条件:每行的首尾都是1

  3. 逐层构建:从上到下逐行生成

  4. 空间利用:利用已生成的行来构建新行


198.打家劫舍

🎭 题目小剧场

想象你是一个神偷,在一条街上作案,但不能抢相邻的两家,因为会触发警报。你需要规划一条路线,在不触发警报的情况下,偷到最多的钱!

💡 解题思路

动态规划解法:

  1. 确定状态:dp[i] 表示到第i家能偷到的最大金额

  2. 状态转移:dp[i] = max(dp[i-1], dp[i-2] + nums[i])

  3. 初始条件:dp[0] = nums[0], dp[1] = max(nums[0], nums[1])

  4. 空间优化:只保留前两个状态

🐍 Python代码实现

class Solution:    def rob(self, nums: List[int]) -> int:        """        动态规划解法(空间优化) - 时间复杂度O(n),空间复杂度O(1)        """        if not nums:            return 0        if len(nums) == 1:            return nums[0]        # dp[i-2] 和 dp[i-1]        prev2, prev1 = nums[0], max(nums[0], nums[1])        for i in range(2len(nums)):            # 当前状态:不偷当前家 vs 偷当前家            current = max(prev1, prev2 + nums[i])            prev2, prev1 = prev1, current        return prev1

📊 复杂度分析

  • 时间复杂度:O(n) - 只需要遍历一次

  • 空间复杂度:O(1) - 只使用常数额外空间

🌟 算法精髓

这个算法的巧妙之处在于"状态压缩"。我们不需要存储所有中间结果,只需要保留前两个状态就能计算出当前状态,大大节省了空间。

🎯 小白友好贴士

  • if not nums: return 0 处理空数组

  • if len(nums) == 1: return nums[0] 处理单元素

  • prev2, prev1 = nums[0], max(nums[0], nums[1]) 初始化前两个状态

  • current = max(prev1, prev2 + nums[i]) 状态转移方程

  • prev2, prev1 = prev1, current 更新状态

🔍 算法执行过程示例

示例:nums = [27931]初始:prev2 = 2, prev1 = max(27= 71步:i = 2, nums[2= 9  current = max(prev1, prev2 + nums[2]) = max(72 + 9= 11  prev2, prev1 = prev1, current = 7112步:i = 3, nums[3= 3  current = max(prev1, prev2 + nums[3]) = max(117 + 3= 11  prev2, prev1 = prev1, current = 11113步:i = 4, nums[4= 1  current = max(prev1, prev2 + nums[4]) = max(1111 + 1= 12  prev2, prev1 = prev1, current = 1112结束:return prev1 = 12 ✅验证:  选择第135家:2 + 9 + 1 = 12  选择第24家:7 + 3 = 10  最优解:12

🎯 核心思想总结

  1. 状态定义:明确dp数组的含义

  2. 状态转移:找到递推关系

  3. 初始条件:确定边界值

  4. 空间优化:减少不必要的存储


279.完全平方数

🎭 题目小剧场

想象你有一堆不同大小的正方形积木(1×1, 2×2, 3×3...),你想用最少数量的积木拼出一个给定的正方形。就像玩俄罗斯方块,要用最少的方块填满整个区域!

💡 解题思路

动态规划解法:

  1. 确定状态:dp[i] 表示组成数字i所需的最少完全平方数数量

  2. 状态转移:dp[i] = min(dp[i - jj] + 1),其中jj ≤ i

  3. 初始条件:dp[0] = 0,其他初始化为无穷大

  4. 逐步计算从1到n的所有状态

🐍 Python代码实现

class Solution:    def numSquares(self, n: int) -> int:        """        动态规划解法 - 时间复杂度O(n√n),空间复杂度O(n)        """        # dp[i] 表示组成数字i所需的最少完全平方数数量        dp = [float('inf')] * (n + 1)        dp[0] = 0  # 0需要0个完全平方数        # 预计算所有可能的完全平方数        squares = []        i = 1        while i * i <= n:            squares.append(i * i)            i += 1        # 动态规划计算        for i in range(1, n + 1):            for square in squares:                if square > i:                    break                dp[i] = min(dp[i], dp[i - square] + 1)        return dp[n]

📊 复杂度分析

  • 时间复杂度:O(n√n) - 外层循环n次,内层循环最多√n次

  • 空间复杂度:O(n) - 需要存储dp数组

🌟 算法精髓

这个算法的巧妙之处在于"分解思想"。将复杂问题分解为子问题,通过子问题的最优解来构建原问题的最优解。

🎯 小白友好贴士

  • dp = [float('inf')] * (n + 1) 初始化dp数组

  • dp[0] = 0 设置初始条件

  • while i * i <= n 预计算完全平方数

  • dp[i] = min(dp[i], dp[i - square] + 1) 状态转移方程

  • return dp[n] 返回最终结果

🔍 算法执行过程示例

示例:n = 121步:预计算完全平方数  squares = [149]2步:动态规划计算初始:dp = [0, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf]  i = 1:    square = 1: dp[1= min(inf, dp[0+ 1= 1    square = 4break (4 > 1)    dp = [01, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf]  i = 2:    square = 1: dp[2= min(inf, dp[1+ 1= 2    square = 4break (4 > 2)    dp = [012, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf]  i = 3:    square = 1: dp[3= min(inf, dp[2+ 1= 3    square = 4break (4 > 3)    dp = [0123, inf, inf, inf, inf, inf, inf, inf, inf, inf]  i = 4:    square = 1: dp[4= min(inf, dp[3+ 1= 4    square = 4: dp[4= min(4, dp[0+ 1= 1    dp = [01231, inf, inf, inf, inf, inf, inf, inf, inf]  i = 5:    square = 1: dp[5= min(inf, dp[4+ 1= 2    square = 4: dp[5= min(2, dp[1+ 1= 2    square = 9break (9 > 5)    dp = [012312, inf, inf, inf, inf, inf, inf, inf]...  i = 12:    square = 1: dp[12= min(inf, dp[11+ 1= 4    square = 4: dp[12= min(4, dp[8+ 1= 3    square = 9: dp[12= min(3, dp[3+ 1= 3    dp = [0123123421233]结束:return dp[12= 3 验证:12 = 4 + 4 + 4 (3个完全平方数)

🎯 核心思想总结

  1. 状态定义:明确dp数组的含义

  2. 状态转移:找到递推关系

  3. 初始条件:确定边界值

  4. 逐步计算:从小到大计算所有状态


322.零钱兑换

🎭 题目小剧场

想象你在自动售货机前,需要用最少的硬币买到饮料。机器里有不同面值的硬币,你需要计算如何组合这些硬币,正好凑齐商品价格,而且用的硬币数量最少!

💡 解题思路

动态规划解法:

  1. 确定状态:dp[i] 表示凑齐金额i所需的最少硬币数量

  2. 状态转移:dp[i] = min(dp[i - coin] + 1),遍历所有硬币面值

  3. 初始条件:dp[0] = 0,其他初始化为无穷大

  4. 逐步计算从1到amount的所有状态

🐍 Python代码实现

class Solution:    def coinChange(self, coins: List[int], amount: int) -> int:        """        动态规划解法 - 时间复杂度O(n×amount),空间复杂度O(amount)        """        if amount < 0:            return -1        # dp[i] 表示凑齐金额i所需的最少硬币数量        dp = [float('inf')] * (amount + 1)        dp[0] = 0  # 凑齐0金额需要0个硬币        # 动态规划计算        for i in range(1, amount + 1):            for coin in coins:                if coin <= i:                    dp[i] = min(dp[i], dp[i - coin] + 1)        return dp[amount] if dp[amount] != float('inf'else -1

📊 复杂度分析

  • 时间复杂度:O(n×amount) - 外层循环amount次,内层循环n次

  • 空间复杂度:O(amount) - 需要存储dp数组

🌟 算法精髓

这个算法的巧妙之处在于"最优子结构"。每个金额的最优解都依赖于更小金额的最优解,通过这种递推关系,我们可以逐步构建出最终答案。

🎯 小白友好贴士

  • dp = [float('inf')] * (amount + 1) 初始化dp数组

  • dp[0] = 0 设置初始条件

  • for coin in coins 遍历所有硬币面值

  • if coin <= i 确保硬币面值不超过当前金额

  • dp[i] = min(dp[i], dp[i - coin] + 1) 状态转移方程

  • return dp[amount] if dp[amount] != float('inf') else -1 处理无解情况

🔍 算法执行过程示例

示例:coins = [134], amount = 6初始:dp = [0, inf, inf, inf, inf, inf, inf]1步:i = 1  coin = 1: dp[1= min(inf, dp[0+ 1= 1  coin = 33 > 1, 跳过  coin = 44 > 1, 跳过  dp = [01, inf, inf, inf, inf, inf]2步:i = 2  coin = 1: dp[2= min(inf, dp[1+ 1= 2  coin = 33 > 2, 跳过  coin = 44 > 2, 跳过  dp = [012, inf, inf, inf, inf]3步:i = 3  coin = 1: dp[3= min(inf, dp[2+ 1= 3  coin = 3: dp[3= min(3, dp[0+ 1= 1  coin = 44 > 3, 跳过  dp = [0121, inf, inf, inf]4步:i = 4  coin = 1: dp[4= min(inf, dp[3+ 1= 2  coin = 3: dp[4= min(2, dp[1+ 1= 2  coin = 4: dp[4= min(2, dp[0+ 1= 1  dp = [01211, inf, inf]5步:i = 5  coin = 1: dp[5= min(inf, dp[4+ 1= 2  coin = 3: dp[5= min(2, dp[2+ 1= 2  coin = 4: dp[5= min(2, dp[1+ 1= 2  dp = [012112, inf]6步:i = 6  coin = 1: dp[6= min(inf, dp[5+ 1= 3  coin = 3: dp[6= min(3, dp[3+ 1= 2  coin = 4: dp[6= min(2, dp[2+ 1= 2  dp = [0121122]结束:return dp[6= 2 验证:6 = 3 + 3 (2个硬币) 或 6 = 4 + 1 + 1 (3个硬币)最优解:2个硬币

🎯 核心思想总结

  1. 状态定义:明确dp数组的含义

  2. 状态转移:找到递推关系

  3. 初始条件:确定边界值

  4. 无解处理:处理无法凑齐的情况


139.单词拆分

🎭 题目小剧场

想象你在玩拼字游戏,有一堆单词卡片,需要判断能否用这些卡片拼出给定的句子。就像用乐高积木搭建模型,每个积木都要严丝合缝地拼接在一起!

💡 解题思路

动态规划解法:

  1. 确定状态:dp[i] 表示字符串前i个字符是否可以被拆分

  2. 状态转移:dp[i] = dp[j] && s[j:i] in wordSet,其中0 ≤ j < i

  3. 初始条件:dp[0] = True(空字符串可以被拆分)

  4. 逐步计算从1到n的所有状态

🐍 Python代码实现

class Solution:    def wordBreak(self, s: str, wordDict: List[str]) -> bool:        """        动态规划解法 - 时间复杂度O(n²),空间复杂度O(n)        """        word_set = set(wordDict)  # 转换为集合,提高查找效率        n = len(s)        dp = [False] * (n + 1)        dp[0] = True  # 空字符串可以被拆分        for i in range(1, n + 1):            for j in range(i):                if dp[j] and s[j:i] in word_set:                    dp[i] = True                    break        return dp[n]

📊 复杂度分析

  • 时间复杂度:O(n²) - 外层循环n次,内层循环最多n次

  • 空间复杂度:O(n) - 需要存储dp数组

🌟 算法精髓

这个算法的巧妙之处在于"分段验证"。我们不直接判断整个字符串,而是将其分解为前缀和后缀,通过动态规划的方式逐步验证每个前缀是否可被拆分。

🎯 小白友好贴士

  • word_set = set(wordDict) 转换为集合,提高查找效率

  • dp = [False] * (n + 1) 初始化dp数组

  • dp[0] = True 设置初始条件

  • for j in range(i) 遍历所有可能的分割点

  • if dp[j] and s[j:i] in word_set 状态转移条件

  • dp[i] = True 标记当前位置可被拆分

  • break 找到一个有效分割即可

🔍 算法执行过程示例

示例:s = "leetcode", wordDict = ["leet""code"]初始:word_set = {"leet""code"}, n = 8dp = [TrueFalseFalseFalseFalseFalseFalseFalseFalse]1步:i = 1, s[0:1] = "l"  j = 0: dp[0] = True"l" not in word_set  dp[1] = False2步:i = 2, s[0:2] = "le"  j = 0: dp[0] = True"le" not in word_set  j = 1: dp[1] = False, 跳过  dp[2] = False3步:i = 3, s[0:3] = "lee"  j = 0: dp[0] = True"lee" not in word_set  j = 1: dp[1] = False, 跳过  j = 2: dp[2] = False, 跳过  dp[3] = False4步:i = 4, s[0:4] = "leet"  j = 0: dp[0] = True"leet" in word_set ✓  dp[4] = Truebreak5步:i = 5, s[0:5] = "leetc"  j = 0: dp[0] = True"leetc" not in word_set  j = 1: dp[1] = False, 跳过  j = 2: dp[2] = False, 跳过  j = 3: dp[3] = False, 跳过  j = 4: dp[4] = True"c" not in word_set  dp[5] = False6步:i = 6, s[0:6] = "leetco"  j = 0: dp[0] = True"leetco" not in word_set  j = 1: dp[1] = False, 跳过  ...  j = 4: dp[4] = True"co" not in word_set  j = 5: dp[5] = False, 跳过  dp[6] = False7步:i = 7, s[0:7] = "leetcod"  j = 0: dp[0] = True"leetcod" not in word_set  ...  j = 4: dp[4] = True"cod" not in word_set  j = 5: dp[5] = False, 跳过  j = 6: dp[6] = False, 跳过  dp[7] = False8步:i = 8, s[0:8] = "leetcode"  j = 0: dp[0] = True"leetcode" not in word_set  j = 1: dp[1] = False, 跳过  ...  j = 4: dp[4] = True"code" in word_set ✓  dp[8] = Truebreak  结束:return dp[8] = True ✅

🎯 核心思想总结

  1. 状态定义:明确dp数组的含义

  2. 状态转移:找到递推关系

  3. 初始条件:确定边界值

  4. 分段验证:逐步验证每个前缀


300.最长递增子序列

🎭 题目小剧场

想象你在玩一个抽牌游戏,每次抽一张牌,你要按顺序摆放,要求后面的牌比前面的大。你想知道最多能摆出多长的递增序列。就像排队,要求后面的人比前面的人高,找出最长的可能队伍!

💡 解题思路

贪心 + 二分查找解法:

  1. 维护一个数组 tails,其中 tails[i] 表示长度为 i+1 的递增子序列的最小末尾元素

  2. 遍历每个数字,用二分查找在 tails 中找到合适的位置

  3. 如果数字比 tails 中所有元素都大,追加到末尾

  4. 否则,替换 tails 中第一个大于等于它的元素

  5. 最终 tails 的长度就是最长递增子序列的长度

🐍 Python代码实现

class Solution:    def lengthOfLIS(self, nums: List[int]) -> int:        """        贪心 + 二分查找解法 - 时间复杂度O(n log n),空间复杂度O(n)        """        if not nums:            return 0        tails = []        for num in nums:            # 二分查找插入位置            left, right = 0len(tails)            while left < right:                mid = (left + right) // 2                if tails[mid] < num:                    left = mid + 1                else:                    right = mid            # 如果left等于tails长度,说明num比所有元素都大            if left == len(tails):                tails.append(num)            else:                tails[left] = num        return len(tails)

📊 复杂度分析

  • 时间复杂度:O(n log n) - n次遍历,每次二分查找O(log n)

  • 空间复杂度:O(n) - 最坏情况下tails数组长度为n

🌟 算法精髓

这个算法的巧妙之处在于"贪心维护"。我们维护的 tails 数组并不是真实的最长递增子序列,但它保证了在相同长度下,末尾元素是最小的,这样为后续元素提供了最大的扩展空间。

🎯 小白友好贴士

  • if not nums: return 0 处理空数组

  • tails = [] 初始化辅助数组

  • while left < right 二分查找模板

  • if tails[mid] < num 判断移动方向

  • if left == len(tails) 判断是否需要追加

  • tails[left] = num 替换对应位置元素

  • return len(tails) 返回最终长度

🔍 算法执行过程示例

示例:nums = [109253710118]初始:tails = []1步:num = 10  二分查找:left = 0right = 0  left == len(tails) (0 == 0) ✓  tails = [10]2步:num = 9  二分查找:  left = 0right = 1, mid = 0  tails[0= 10 >= 9right = 0  left = 0right = 0, 结束  left != len(tails) (0 != 1) ✗  tails[0= 9  tails = [9]3步:num = 2  二分查找:  left = 0right = 1, mid = 0  tails[0= 9 >= 2right = 0  left = 0right = 0, 结束  left != len(tails) (0 != 1) ✗  tails[0= 2  tails = [2]4步:num = 5  二分查找:  left = 0right = 1, mid = 0  tails[0= 2 < 5left = 1  left = 1right = 1, 结束  left == len(tails) (1 == 1) ✓  tails.append(5)  tails = [25]5步:num = 3  二分查找:  left = 0right = 2, mid = 1  tails[1= 5 >= 3right = 1  left = 0right = 1, mid = 0  tails[0= 2 < 3left = 1  left = 1right = 1, 结束  left != len(tails) (1 != 2) ✗  tails[1= 3  tails = [23]6步:num = 7  二分查找:  left = 0right = 2, mid = 1  tails[1= 3 < 7left = 2  left = 2right = 2, 结束  left == len(tails) (2 == 2) ✓  tails.append(7)  tails = [237]7步:num = 101  二分查找:  left = 0right = 3, mid = 1  tails[1= 3 < 101left = 2  left = 2right = 3, mid = 2  tails[2= 7 < 101left = 3  left = 3right = 3, 结束  left == len(tails) (3 == 3) ✓  tails.append(101)  tails = [237101]8步:num = 18  二分查找:  left = 0right = 4, mid = 2  tails[2= 7 < 18left = 3  left = 3right = 4, mid = 3  tails[3= 101 >= 18right = 3  left = 3right = 3, 结束  left != len(tails) (3 != 4) ✗  tails[3= 18  tails = [23718]结束:return len(tails) = 4 ✅验证:最长递增子序列为 [23718] 或 [237101]

🎯 核心思想总结

  1. 贪心策略:维护尽可能小的末尾元素

  2. 二分查找:快速找到插入位置

  3. 动态维护:不断更新tails数组

  4. 长度即答案:tails长度就是LIS长度


152.乘积最大子数组

🎭 题目小剧场

想象你在玩一个数字连连看游戏,每个数字都有正负,你要找出一段连续的数字,让它们的乘积最大。就像在股市中寻找最佳买入卖出点,需要考虑涨跌的相互影响!

💡 解题思路

动态规划解法:

  1. 确定状态:同时维护当前最大值和最小值

  2. 状态转移:遇到负数时,最大值和最小值会互换

  3. 初始条件:第一个数字既是最大值也是最小值

  4. 逐步计算并更新全局最大值

🐍 Python代码实现

class Solution:    def maxProduct(self, nums: List[int]) -> int:        """        动态规划解法 - 时间复杂度O(n),空间复杂度O(1)        """        if not nums:            return 0        # 维护当前最大值和最小值        current_max = current_min = result = nums[0]        for i in range(1len(nums)):            num = nums[i]            # 如果当前数字是负数,最大值和最小值会互换            if num < 0:                current_max, current_min = current_min, current_max            # 更新当前最大值和最小值            current_max = max(num, current_max * num)            current_min = min(num, current_min * num)            # 更新全局最大值            result = max(result, current_max)        return result

📊 复杂度分析

  • 时间复杂度:O(n) - 只需要遍历一次

  • 空间复杂度:O(1) - 只使用常数额外空间

🌟 算法精髓

这个算法的巧妙之处在于"双重维护"。我们不仅维护最大值,还维护最小值,因为负数会反转大小关系,最小值乘以负数可能变成最大值。

🎯 小白友好贴士

  • if not nums: return 0 处理空数组

  • current_max = current_min = result = nums[0] 初始化状态

  • if num < 0 处理负数情况

  • current_max, current_min = current_min, current_max 交换最大最小值

  • current_max = max(num, current_max * num) 更新最大值

  • current_min = min(num, current_min * num) 更新最小值

  • result = max(result, current_max) 更新全局最大值

🔍 算法执行过程示例

示例:nums = [23-24]初始:current_max = current_min = result = 21步:num = 3  num > 0,不需要交换  current_max = max(32 * 3= 6  current_min = min(32 * 3= 3  result = max(26= 62步:num = -2  num < 0,交换最大最小值  current_max, current_min = current_min, current_max = 36  current_max = max(-23 * -2= -2  current_min = min(-26 * -2= -12  result = max(6-2= 63步:num = 4  num > 0,不需要交换  current_max = max(4-2 * 4= 4  current_min = min(4-12 * 4= -48  result = max(64= 6结束:return result = 6 ✅验证:最大乘积子数组为 [23],乘积为 6

🎯 核心思想总结

  1. 双重维护:同时维护最大值和最小值

  2. 负数处理:遇到负数时交换最大最小值

  3. 状态转移:考虑选择当前数字或延续之前的乘积

  4. 全局更新:每步都更新全局最大值


416.分割等和子集

🎭 题目小剧场

想象你有一堆不同重量的砝码,要放在天平的两边,让天平完美平衡。你需要判断是否可能将这些砝码分成两组,使两组的总重量完全相等!

💡 解题思路

动态规划解法(0-1背包问题):

  1. 问题转化:判断能否从数组中选出若干数,使其和等于总和的一半

  2. 确定状态:dp[i] 表示能否凑出和为i

  3. 状态转移:dp[i] = dp[i] or dp[i - num]

  4. 遍历顺序:从后往前遍历,确保每个元素只使用一次

🐍 Python代码实现

class Solution:    def canPartition(self, nums: List[int]) -> bool:        """        动态规划解法 - 时间复杂度O(n×target),空间复杂度O(target)        """        total_sum = sum(nums)        # 如果总和为奇数,无法分割        if total_sum % 2 != 0:            return False        target = total_sum // 2        # dp[i] 表示能否凑出和为i        dp = [False] * (target + 1)        dp[0] = True  # 和为0总是可以(不选任何元素)        for num in nums:            # 从后往前遍历,避免重复使用            for i in range(target, num - 1, -1):                dp[i] = dp[i] or dp[i - num]        return dp[target]

📊 复杂度分析

  • 时间复杂度:O(n×target) - n是数组长度,target是目标和

  • 空间复杂度:O(target) - 需要大小为target+1的dp数组

🌟 算法精髓

这个算法的巧妙之处在于"问题转化"。将分割问题转化为0-1背包问题,用动态规划求解子集和的可能性,从而判断是否能够等分。

🎯 小白友好贴士

  • total_sum = sum(nums) 计算数组总和

  • if total_sum % 2 != 0 奇数总和直接返回False

  • target = total_sum // 2 计算目标和

  • dp = [False] * (target + 1) 初始化dp数组

  • dp[0] = True 和为0总是可以

  • for i in range(target, num - 1, -1) 逆序遍历

  • dp[i] = dp[i] or dp[i - num] 状态转移方程

🔍 算法执行过程示例

示例:nums = [15115]初始:total_sum = 22, target = 11dp = [TrueFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalse]1步:num = 1  i从111  i = 11: dp[11] = dp[11or dp[10] = False or False = False  i = 10: dp[10] = dp[10or dp[9] = False or False = False  ...  i = 1: dp[1] = dp[1or dp[0] = False or True = True  dp = [TrueTrueFalseFalseFalseFalseFalseFalseFalseFalseFalseFalse]2步:num = 5  i从115  i = 11: dp[11] = dp[11or dp[6] = False or False = False  i = 10: dp[10] = dp[10or dp[5] = False or False = False  i = 9: dp[9] = dp[9or dp[4] = False or False = False  i = 8: dp[8] = dp[8or dp[3] = False or False = False  i = 7: dp[7] = dp[7or dp[2] = False or False = False  i = 6: dp[6] = dp[6or dp[1] = False or True = True  i = 5: dp[5] = dp[5or dp[0] = False or True = True  dp = [TrueTrueFalseFalseFalseTrueTrueFalseFalseFalseFalseFalse]3步:num = 11  i从1111  i = 11: dp[11] = dp[11or dp[0] = False or True = True  dp = [TrueTrueFalseFalseFalseTrueTrueFalseFalseFalseFalseTrue]4步:num = 5  i从115  i = 11: dp[11] = dp[11or dp[6] = True or True = True  i = 10: dp[10] = dp[10or dp[5] = False or True = True  i = 9: dp[9] = dp[9or dp[4] = False or False = False  i = 8: dp[8] = dp[8or dp[3] = False or False = False  i = 7: dp[7] = dp[7or dp[2] = False or False = False  i = 6: dp[6] = dp[6or dp[1] = True or True = True  i = 5: dp[5] = dp[5or dp[0] = True or True = True  dp = [TrueTrueFalseFalseFalseTrueTrueFalseFalseFalseTrueTrue]结束:return dp[11] = True ✅验证:可以分割为 [155] 和 [11],和都为11

🎯 核心思想总结

  1. 问题转化:将分割问题转化为子集和问题

  2. 状态定义:明确dp数组的含义

  3. 状态转移:找到递推关系

  4. 逆序遍历:确保每个元素只使用一次


32.最长有效括号

🎭 题目小剧场

想象你在玩一个配对游戏,有一堆左括号 ( 和右括号 ),你要找出最长的连续序列,让它们都能完美配对。就像玩连连看,需要找到最长的有效连线!

💡 解题思路

栈 + 动态规划解法:

  1. 使用栈记录括号的位置,栈底保存最后一个未匹配的右括号位置

  2. 遇到左括号时,将其位置入栈

  3. 遇到右括号时,弹出栈顶元素

  4. 如果栈为空,说明当前右括号无法匹配,将其位置入栈

  5. 如果栈不为空,计算当前有效长度:i - stack[-1]

  6. 维护最大长度

🐍 Python代码实现

class Solution:    def longestValidParentheses(self, s: str) -> int:        """        栈 + 动态规划解法 - 时间复杂度O(n),空间复杂度O(n)        """        max_length = 0        stack = [-1]  # 栈底保存最后一个未匹配的右括号位置        for i, char in enumerate(s):            if char == '(':                stack.append(i)            else:                stack.pop()                if not stack:                    stack.append(i)  # 当前右括号无法匹配                else:                    max_length = max(max_length, i - stack[-1])        return max_length

📊 复杂度分析

  • 时间复杂度:O(n) - 只需要遍历一次

  • 空间复杂度:O(n) - 最坏情况下栈的大小为n

🌟 算法精髓

这个算法的巧妙之处在于"位置记录"。我们不直接记录括号,而是记录它们的位置,通过位置差来计算有效长度,同时用栈底元素作为分界点。

🎯 小白友好贴士

  • stack = [-1] 初始化栈,-1作为虚拟边界

  • if char == '(' 左括号入栈

  • stack.pop() 右括号出栈

  • if not stack 栈为空说明无法匹配

  • stack.append(i) 无法匹配的右括号作为新边界

  • max_length = max(max_length, i - stack[-1]) 计算有效长度

🔍 算法执行过程示例

示例:s = ")()())"初始:max_length = 0, stack = [-1]1步:i = 0char = ')'  stack.pop() → stack = []  栈为空,无法匹配,stack.append(0)  stack = [0]  max_length = 02步:i = 1char = '('  左括号入栈  stack = [01]  max_length = 03步:i = 2char = ')'  stack.pop() → stack = [0]  栈不为空,计算长度:2 - 0 = 2  max_length = max(02) = 2  stack = [0]4步:i = 3char = '('  左括号入栈  stack = [03]  max_length = 25步:i = 4char = ')'  stack.pop() → stack = [0]  栈不为空,计算长度:4 - 0 = 4  max_length = max(24) = 4  stack = [0]6步:i = 5char = ')'  stack.pop() → stack = []  栈为空,无法匹配,stack.append(5)  stack = [5]  max_length = 4结束:return max_length = 4 ✅验证:最长有效括号为 "()()",长度为4

🎯 核心思想总结

  1. 位置记录:用栈记录括号位置而非括号本身

  2. 边界管理:栈底元素作为分界点

  3. 长度计算:通过位置差计算有效长度

  4. 动态更新:实时维护最大长度

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-02-08 22:31:22 HTTP/2.0 GET : https://f.mffb.com.cn/a/463074.html
  2. 运行时间 : 0.090415s [ 吞吐率:11.06req/s ] 内存消耗:4,674.95kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=90f5f744519fb2541b2f303e95fcea3f
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000471s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000710s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000293s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000278s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000534s ]
  6. SELECT * FROM `set` [ RunTime:0.000214s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000519s ]
  8. SELECT * FROM `article` WHERE `id` = 463074 LIMIT 1 [ RunTime:0.000772s ]
  9. UPDATE `article` SET `lasttime` = 1770561082 WHERE `id` = 463074 [ RunTime:0.002367s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000275s ]
  11. SELECT * FROM `article` WHERE `id` < 463074 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000451s ]
  12. SELECT * FROM `article` WHERE `id` > 463074 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000438s ]
  13. SELECT * FROM `article` WHERE `id` < 463074 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.002830s ]
  14. SELECT * FROM `article` WHERE `id` < 463074 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.001185s ]
  15. SELECT * FROM `article` WHERE `id` < 463074 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.001375s ]
0.094383s