当前位置:首页>python>Python版_Leetcode_hot100系列(10)--回溯

Python版_Leetcode_hot100系列(10)--回溯

  • 2026-01-17 18:26:02
Python版_Leetcode_hot100系列(10)--回溯

46.全排列

🎭 题目小剧场

想象你有几个不同颜色的球,要把它们排成一排。你需要尝试所有可能的排列方式。每次选一个球放在当前位置,然后继续排列剩下的球,直到所有球都排完。这就是全排列的本质!

💡 解题思路

回溯算法解法:

  1. 使用递归逐个位置填充数字

  2. 用 used 数组标记已使用的数字

  3. 每个位置尝试所有未使用的数字

  4. 递归到下一位置,完成后回溯状态

  5. 当排列长度等于数组长度时,记录结果

🐍 Python代码实现

class Solution:    def permute(self, nums: List[int]) -> List[List[int]]:        """        回溯算法 - 时间复杂度O(n!×n),空间复杂度O(n)        """        n = len(nums)        result = []        used = [False] * n        current = []        def backtrack():            """递归生成排列"""            if len(current) == n:                result.append(current.copy())                return            for i in range(n):                if not used[i]:                    # 选择数字                    used[i] = True                    current.append(nums[i])                    # 递归到下一位置                    backtrack()                    # 回溯:撤销选择                    current.pop()                    used[i] = False        backtrack()        return result

📊 复杂度分析

  • 时间复杂度:O(n!×n) - n!个排列,每个需要O(n)复制

  • 空间复杂度:O(n) - 递归调用栈和临时数组

🌟 算法精髓

回溯算法的巧妙之处在于"尝试-递归-撤销"的模式。在每个位置尝试所有可能的选择,然后递归处理下一位置,最后撤销选择回到原状态,继续尝试其他可能性。

🎯 小白友好贴士

  • used[i] = True 标记数字已使用

  • current.append(nums[i]) 选择数字加入当前排列

  • backtrack() 递归处理下一位置

  • current.pop() 撤销选择

  • used[i] = False 取消标记

🔍 算法执行过程示例

nums = [1,2,3]backtrack():├── 选择1: current=[1], used=[T,F,F]│   ├── backtrack():│   │   ├── 选择2: current=[1,2], used=[T,T,F]│   │   │   ├── backtrack():│   │   │   │   ├── 选择3: current=[1,2,3], used=[T,T,T]│   │   │   │   │   len=3 → result=[[1,2,3]]│   │   │   │   ├── 撤销3: current=[1,2], used=[T,T,F]│   │   │   │   └── return│   │   │   ├── 撤销2: current=[1], used=[T,F,F]│   │   │   └── return│   │   ├── 选择3: current=[1,3], used=[T,F,T]│   │   │   ├── backtrack():│   │   │   │   ├── 选择2: current=[1,3,2], used=[T,T,T]│   │   │   │   │   len=3 → result=[[1,2,3],[1,3,2]]│   │   │   │   ├── 撤销2: current=[1,3], used=[T,F,T]│   │   │   │   └── return│   │   │   ├── 撤销3: current=[1], used=[T,F,F]│   │   │   └── return│   │   └── return│   ├── 撤销1: current=[], used=[F,F,F]│   └── return├── 选择2: current=[2], used=[F,T,F]│   ├── (类似过程,生成[2,1,3], [2,3,1])│   └── return├── 选择3: current=[3], used=[F,F,T]│   ├── (类似过程,生成[3,1,2], [3,2,1])│   └── return└── return最终结果:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] ✅

🎯 核心思想总结

  1. 递归生成:逐个位置填充数字

  2. 状态管理:用used数组标记已使用数字

  3. 回溯机制:尝试后撤销,恢复原状态

  4. 结果收集:完整排列时记录结果


78.子集

🎭 题目小剧场

想象你有一组不同颜色的积木,要找出所有可能的组合方式。你可以选择用0个、1个、2个...直到全部积木。每个积木要么选择,要么不选择,这就是子集问题的本质!

💡 解题思路

回溯算法解法:

  1. 从起始位置开始,逐个考虑每个元素

  2. 对于每个元素,有两种选择:包含或不包含

  3. 每到一个新位置,记录当前子集

  4. 递归处理后续元素

  5. 回溯时撤销当前选择

🐍 Python代码实现

class Solution:    def subsets(self, nums: List[int]) -> List[List[int]]:        """        回溯算法 - 时间复杂度O(2^n×n),空间复杂度O(n)        """        result = []        current = []        def backtrack(start):            """递归生成子集"""            # 每到一个新位置就记录当前子集            result.append(current.copy())            # 从start开始,避免重复组合            for i in range(start, len(nums)):                # 选择当前元素                current.append(nums[i])                # 递归处理后续元素                backtrack(i + 1)                # 回溯:撤销选择                current.pop()        backtrack(0)        return result

📊 复杂度分析

  • 时间复杂度:O(2^n×n) - 2^n个子集,每个需要O(n)复制

  • 空间复杂度:O(n) - 递归调用栈和临时数组

🌟 算法精髓

这个算法的巧妙之处在于"逐步构建"。每到一个新位置就记录当前状态,然后继续向下探索。通过 start 参数确保每个元素只考虑一次,避免了重复组合。

🎯 小白友好贴士

  • result.append(current.copy()) 记录当前子集

  • for i in range(start, len(nums)) 从start开始避免重复

  • current.append(nums[i]) 选择当前元素

  • backtrack(i + 1) 递归处理后续元素

  • current.pop() 回溯撤销选择

🔍 算法执行过程示例

nums = [1,2,3]backtrack(0):├── result.append([]) → result=[[]]├── i=0: 选择1, current=[1]│   ├── backtrack(1):│   │   ├── result.append([1]) → result=[[],[1]]│   │   ├── i=1: 选择2, current=[1,2]│   │   │   ├── backtrack(2):│   │   │   │   ├── result.append([1,2]) → result=[[],[1],[1,2]]│   │   │   │   ├── i=2: 选择3, current=[1,2,3]│   │   │   │   │   ├── backtrack(3):│   │   │   │   │   │   ├── result.append([1,2,3]) → result=[[],[1],[1,2],[1,2,3]]│   │   │   │   │   │   └── return│   │   │   │   │   ├── 撤销3: current=[1,2]│   │   │   │   │   └── return│   │   │   │   └── return│   │   │   ├── 撤销2: current=[1]│   │   │   └── return│   │   ├── i=2: 选择3, current=[1,3]│   │   │   ├── backtrack(3):│   │   │   │   ├── result.append([1,3]) → result=[[],[1],[1,2],[1,2,3],[1,3]]│   │   │   │   └── return│   │   │   ├── 撤销3: current=[1]│   │   │   └── return│   │   └── return│   ├── 撤销1: current=[]│   └── return├── i=1: 选择2, current=[2]│   ├── backtrack(2):│   │   ├── result.append([2]) → result=[[],[1],[1,2],[1,2,3],[1,3],[2]]│   │   ├── i=2: 选择3, current=[2,3]│   │   │   ├── backtrack(3):│   │   │   │   ├── result.append([2,3]) → result=[[],[1],[1,2],[1,2,3],[1,3],[2],[2,3]]│   │   │   │   └── return│   │   │   ├── 撤销3: current=[2]│   │   │   └── return│   │   └── return│   ├── 撤销2: current=[]│   └── return├── i=2: 选择3, current=[3]│   ├── backtrack(3):│   │   ├── result.append([3]) → result=[[],[1],[1,2],[1,2,3],[1,3],[2],[2,3],[3]]│   │   └── return│   ├── 撤销3: current=[]│   └── return└── return最终结果:[[],[1],[1,2],[1,2,3],[1,3],[2],[2,3],[3]] ✅

🎯 核心思想总结

  1. 逐步构建:每到一个新位置就记录当前状态

  2. 选择机制:每个元素可以选择包含或不包含

  3. 避免重复:使用start参数确保顺序

  4. 回溯撤销:尝试后恢复原状态


17.电话号码的字母组合

🎭 题目小剧场

想象你在用老式手机发短信,每个数字键对应几个字母。你要输入一串数字,找出所有可能的字母组合。就像在手机上按数字键,每个数字都有多种选择,你需要把所有可能的组合都试一遍!

💡 解题思路

回溯算法解法:

  1. 建立数字到字母的映射表

  2. 逐个处理数字,尝试所有可能的字母

  3. 递归构建组合,每次添加一个字母

  4. 当组合长度等于输入长度时,记录结果

  5. 回溯时撤销最后一个字母,尝试其他选择

🐍 Python代码实现

class Solution:    def letterCombinations(self, digits: str) -> List[str]:        """        回溯算法 - 时间复杂度O(3^n×4^m),空间复杂度O(n)        """        if not digits:            return []        # 数字到字母的映射        phone_map = {            '2''abc',            '3''def',            '4''ghi',            '5''jkl',            '6''mno',            '7''pqrs',            '8''tuv',            '9''wxyz'        }        result = []        current = []        def backtrack(index):            """递归构建字母组合"""            if index == len(digits):                result.append(''.join(current))                return            # 获取当前数字对应的所有字母            digit = digits[index]            letters = phone_map[digit]            # 尝试每个字母            for letter in letters:                current.append(letter)                backtrack(index + 1)                current.pop()        backtrack(0)        return result

📊 复杂度分析

  • 时间复杂度:O(3^n×4^m) - n是输入中对应3个字母的数字个数,m是对应4个字母的数字个数

  • 空间复杂度:O(n) - 递归调用栈和临时数组

🌟 算法精髓

这个算法的巧妙之处在于"逐位构建"。每个数字位置独立处理,通过递归深度控制当前处理的位置,确保组合的顺序和完整性。

🎯 小白友好贴士

  • phone_map 数字到字母的映射表

  • backtrack(index) 处理第index个数字

  • for letter in letters 尝试当前数字的所有字母

  • current.append(letter) 选择字母加入组合

  • current.pop() 回溯撤销选择

🔍 算法执行过程示例

digits = "23"phone_map = {'2''abc''3''def'}backtrack(0):├── digit = '2', letters = 'abc'├── 尝试'a': current=['a']│   ├── backtrack(1):│   │   ├── digit = '3', letters = 'def'│   │   ├── 尝试'd': current=['a','d']│   │   │   ├── backtrack(2): index=2==len(digits)=2 → result=['ad']│   │   │   ├── current=['a']│   │   │   └── return│   │   ├── 尝试'e': current=['a','e']│   │   │   ├── backtrack(2): → result=['ad','ae']│   │   │   ├── current=['a']│   │   │   └── return│   │   ├── 尝试'f': current=['a','f']│   │   │   ├── backtrack(2): → result=['ad','ae','af']│   │   │   ├── current=['a']│   │   │   └── return│   │   └── return│   ├── current=[]│   └── return├── 尝试'b': current=['b']│   ├── backtrack(1):│   │   ├── (类似过程,生成'bd','be','bf')│   │   └── return│   ├── current=[]│   └── return├── 尝试'c': current=['c']│   ├── backtrack(1):│   │   ├── (类似过程,生成'cd','ce','cf')│   │   └── return│   ├── current=[]│   └── return└── return最终结果:["ad","ae","af","bd","be","bf","cd","ce","cf"] ✅

🎯 核心思想总结

  1. 映射转换:数字转换为对应的字母集合

  2. 逐位处理:按顺序处理每个数字位

  3. 递归构建:每次添加一个字母到组合中

  4. 回溯机制:尝试后撤销,继续其他选择


39.组合总和

🎭 题目小剧场

想象你在自助餐厅取餐,每道菜可以重复取多次,但总重量必须正好等于目标值。你需要找出所有可能的取餐组合。这就是组合总和问题!

💡 解题思路

回溯算法解法:

  1. 对候选数组排序,便于剪枝

  2. 递归尝试每个候选数字

  3. 每个数字可以重复使用,所以递归时传入相同索引

  4. 当前和超过目标时剪枝

  5. 当前和等于目标时记录结果

🐍 Python代码实现

class Solution:    def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:        """        回溯算法 - 时间复杂度O(n^(target/min)),空间复杂度O(target/min)        """        candidates.sort()  # 排序便于剪枝        result = []        current = []        def backtrack(start, current_sum):            """递归寻找组合"""            if current_sum == target:                result.append(current.copy())                return            if current_sum > target:                return            for i in range(start, len(candidates)):                num = candidates[i]                # 剪枝:如果当前数字会让总和超过目标,直接跳过                if current_sum + num > target:                    break                # 选择当前数字                current.append(num)                # 递归,注意传入i(可以重复使用)                backtrack(i, current_sum + num)                # 回溯:撤销选择                current.pop()        backtrack(00)        return result

📊 复杂度分析

  • 时间复杂度:O(n^(target/min)) - 最坏情况需要大量组合

  • 空间复杂度:O(target/min) - 递归深度最大为目标除以最小值

🌟 算法精髓

这个算法的巧妙之处在于"可重复使用"和"剪枝优化"。通过传入相同索引允许重复使用数字,通过排序和提前终止避免无效搜索。

🎯 小白友好贴士

  • candidates.sort() 排序便于剪枝

  • backtrack(i, current_sum + num) 传入i允许重复使用

  • if current_sum + num > target: break 剪枝优化

  • current.append(num) 选择数字

  • current.pop() 回溯撤销选择

🔍 算法执行过程示例

candidates = [2,3,6,7], target = 7排序后:[2,3,6,7]backtrack(00):├── i=0, num=2, current_sum=0│   ├── 选择2: current=[2], current_sum=2│   │   ├── backtrack(02):│   │   │   ├── i=0, num=2, current_sum=2│   │   │   │   ├── 选择2: current=[2,2], current_sum=4│   │   │   │   │   ├── backtrack(04):│   │   │   │   │   │   ├── i=0, num=2, current_sum=4│   │   │   │   │   │   │   ├── 选择2: current=[2,2,2], current_sum=6│   │   │   │   │   │   │   │   ├── backtrack(06):│   │   │   │   │   │   │   │   │   ├── i=0, num=2, current_sum=6│   │   │   │   │   │   │   │   │   │   ├── current_sum+2=8 > 7 → break│   │   │   │   │   │   │   │   │   ├── i=1, num=3, current_sum=6│   │   │   │   │   │   │   │   │   │   ├── 选择3: current=[2,2,2,3], current_sum=9 > 7 → break│   │   │   │   │   │   │   │   │   └── return│   │   │   │   │   │   │   │   ├── 撤销3: current=[2,2,2]│   │   │   │   │   │   │   │   └── return│   │   │   │   │   │   │   ├── 撤销2: current=[2,2,2]│   │   │   │   │   │   │   └── return│   │   │   │   │   │   ├── i=1, num=3, current_sum=4│   │   │   │   │   │   │   ├── 选择3: current=[2,2,3], current_sum=7│   │   │   │   │   │   │   │   ├── backtrack(17):│   │   │   │   │   │   │   │   │   ├── current_sum == target → result=[[2,2,3]]│   │   │   │   │   │   │   │   │   └── return│   │   │   │   │   │   │   │   ├── 撤销3: current=[2,2]│   │   │   │   │   │   │   │   └── return│   │   │   │   │   │   │   └── return│   │   │   │   │   │   └── return│   │   │   │   ├── 撤销2: current=[2,2]│   │   │   │   └── return│   │   │   └── return│   │   └── return│   └── return├── i=1, num=3, current_sum=0│   ├── (类似过程,不会产生有效组合)│   └── return├── i=2, num=6, current_sum=0│   ├── (类似过程,不会产生有效组合)│   └── return├── i=3, num=7, current_sum=0│   ├── 选择7: current=[7], current_sum=7│   │   ├── backtrack(37):│   │   │   ├── current_sum == target → result=[[2,2,3],[7]]│   │   │   └── return│   │   ├── 撤销7: current=[]│   │   └── return│   └── return└── return最终结果:[[2,2,3],[7]] ✅

🎯 核心思想总结

  1. 可重复使用:递归时传入相同索引

  2. 剪枝优化:排序后提前终止无效搜索

  3. 回溯机制:尝试后撤销,继续其他选择

  4. 目标控制:精确控制总和等于目标值


22.括号生成

🎭 题目小剧场

想象你在搭积木,积木只有两种:左括号 ( 和右括号 )。你需要搭出 n 对括号,而且任何时候已经搭好的部分都必须是"合法"的(不能有右括号比左括号多)。这就是括号生成问题!

💡 解题思路

回溯算法解法:

  1. 维护当前已使用的左右括号数量

  2. 只要左括号数量小于 n,就可以添加左括号

  3. 只要右括号数量小于左括号数量,就可以添加右括号

  4. 当总长度达到 2n 时,记录结果

🐍 Python代码实现

class Solution:    def generateParenthesis(self, n: int) -> List[str]:        """        回溯算法 - 时间复杂度O(4^n/√n),空间复杂度O(n)        """        result = []        current = []        def backtrack(left_count, right_count):            """递归生成括号组合"""            # 当长度达到2n时,记录结果            if len(current) == 2 * n:                result.append(''.join(current))                return            # 只要左括号数量小于n,就可以添加左括号            if left_count < n:                current.append('(')                backtrack(left_count + 1, right_count)                current.pop()            # 只要右括号数量小于左括号数量,就可以添加右括号            if right_count < left_count:                current.append(')')                backtrack(left_count, right_count + 1)                current.pop()        backtrack(00)        return result

📊 复杂度分析

  • 时间复杂度:O(4^n/√n) - 第n个卡特兰数

  • 空间复杂度:O(n) - 递归调用栈和临时数组

🌟 算法精髓

这个算法的巧妙之处在于"合法性约束"。通过维护左右括号的数量关系,确保生成的每个中间状态都是合法的,从而避免了生成无效组合。

🎯 小白友好贴士

  • left_count 已使用的左括号数量

  • right_count 已使用的右括号数量

  • if left_count < n 可以添加左括号

  • if right_count < left_count 可以添加右括号

  • len(current) == 2 * n 达到目标长度

🔍 算法执行过程示例

= 3backtrack(00):├── 添加'('current=['('], left_count=1, right_count=0│   ├── backtrack(10):│   │   ├── 添加'('current=['(','('], left_count=2, right_count=0│   │   │   ├── backtrack(20):│   │   │   │   ├── 添加'('current=['(','(','('], left_count=3, right_count=0│   │   │   │   │   ├── backtrack(30):│   │   │   │   │   │   ├── 添加')'current=['(','(','(','), left_count=3, right_count=1│   │   │   │   │   │   │   ├── backtrack(3, 1):│   │   │   │   │   │   │   │   ├── 添加')': current=['(','(','(','),'), left_count=3, right_count=2│   │   │   │   │   │   │   │   │   ├── backtrack(3, 2):│   │   │   │   │   │   │   │   │   │   ├── 添加')': current=['(','(','(','),','),'], left_count=3, right_count=3│   │   │   │   │   │   │   │   │   │   │   ├── len=6 → result=["((()))"]│   │   │   │   │   │   │   │   │   │   │   └── return│   │   │   │   │   │   │   │   │   │   └── return│   │   │   │   │   │   │   │   │   └── return│   │   │   │   │   │   │   │   └── return│   │   │   │   │   │   │   └── return│   │   │   │   │   │   └── return│   │   │   │   │   └── return│   │   │   │   └── return│   │   │   └── return│   │   └── return│   └── return├── (继续其他分支,生成所有组合)└── return最终结果:["((()))","(()())","(())()","()(())","()()()"] ✅

🎯 核心思想总结

  1. 数量控制:精确控制左右括号的使用数量

  2. 合法性约束:确保右括号不超过左括号

  3. 递归构建:逐步构建括号字符串

  4. 回溯机制:尝试后撤销,继续其他选择


79.单词搜索

🎭 题目小剧场

想象你在玩字谜游戏,需要在字母网格中找到隐藏的单词。你可以从任意位置开始,上下左右移动,但不能重复经过同一个格子。这就是单词搜索问题!

💡 解题思路

DFS回溯解法:

  1. 遍历网格,寻找单词的起始位置

  2. 从每个可能的起始位置开始DFS搜索

  3. 使用回溯算法,标记已访问的格子

  4. 每次向四个方向扩展,匹配下一个字符

  5. 找到完整单词返回true,否则返回false

🐍 Python代码实现

class Solution:    def exist(self, board: List[List[str]], word: str) -> bool:        """        DFS回溯算法 - 时间复杂度O(mn×4^L),空间复杂度O(L)        """        m, n = len(board), len(board[0])        word_len = len(word)        def dfs(i, j, index):            """递归搜索单词"""            # 边界检查和字符匹配            if i < 0 or i >= m or j < 0 or j >= n or board[i][j] != word[index]:                return False            # 找到完整单词            if index == word_len - 1:                return True            # 标记当前格子为已访问            temp = board[i][j]            board[i][j] = '#'            # 向四个方向扩展            found = (dfs(i - 1, j, index + 1or  # 上                    dfs(i + 1, j, index + 1or  # 下                    dfs(i, j - 1, index + 1or  # 左                    dfs(i, j + 1, index + 1))    # 右            # 回溯:恢复原始字符            board[i][j] = temp            return found        # 遍历所有可能的起始位置        for i in range(m):            for j in range(n):                if board[i][j] == word[0]:  # 优化:只从匹配首字符的位置开始                    if dfs(i, j, 0):                        return True        return False

📊 复杂度分析

  • 时间复杂度:O(mn×4^L) - mn个起始位置,每个位置最多4^L条路径

  • 空间复杂度:O(L) - 递归调用栈深度

🌟 算法精髓

这个算法的巧妙之处在于"原地标记"。通过临时修改格子字符来标记访问状态,避免了额外的空间开销,同时确保不会重复使用同一个格子。

🎯 小白友好贴士

  • if board[i][j] == word[0] 优化:只从匹配首字符的位置开始

  • board[i][j] = '#' 标记格子为已访问

  • index == word_len - 1 找到完整单词

  • dfs(i ± 1, j) 上下方向扩展

  • board[i][j] = temp 回溯恢复原始字符

🔍 算法执行过程示例

board = [['A','B','C','E'],         ['S','F','C','S'],         ['A','D','E','E']], word = "ABCCED"搜索过程:1. 从(0,0)='A'开始,匹配"A"   dfs(0,0,0):   ├── 标记(0,0)='#'   ├── 上:越界   ├── 下:dfs(1,0,1) → board[1][0]='S' != word[1]='B' → False   ├── 左:越界   ├── 右:dfs(0,1,1) → board[0][1]='B' == word[1]='B' → True   │   ├── 标记(0,1)='#'   │   ├── dfs(-1,1,2) → 越界   │   ├── dfs(1,1,2) → board[1][1]='F' != word[2]='C' → False   │   ├── dfs(0,0,2) → board[0][0]='#' != word[2]='C' → False   │   ├── dfs(0,2,2) → board[0][2]='C' == word[2]='C' → True   │   │   ├── 标记(0,2)='#'   │   │   ├── dfs(-1,2,3) → 越界   │   │   ├── dfs(1,2,3) → board[1][2]='C' == word[3]='C' → True   │   │   │   ├── 标记(1,2)='#'   │   │   │   ├── dfs(0,2,4) → board[0][2]='#' != word[4]='E' → False   │   │   │   ├── dfs(2,2,4) → board[2][2]='E' == word[4]='E' → True   │   │   │   │   ├── 标记(2,2)='#'   │   │   │   │   ├── dfs(1,2,5) → board[1][2]='#' != word[5]='D' → False   │   │   │   │   ├── dfs(3,2,5) → 越界   │   │   │   │   ├── dfs(2,1,5) → board[2][1]='D' == word[5]='D' → True   │   │   │   │   │   ├── index=5 == len(word)-1 → 找到完整单词!   │   │   │   │   │   └── return True   │   │   │   │   └── return True   │   │   │   └── return True   │   │   └── return True   │   └── return True   └── return True最终结果:True ✅路径:A(0,0) → B(0,1) → C(0,2) → C(1,2) → E(2,2) → D(2,1)

🎯 核心思想总结

  1. 多起点搜索:从所有匹配首字符的位置开始

  2. 方向扩展:每次向四个方向尝试

  3. 访问标记:原地标记避免重复访问

  4. 回溯恢复:尝试后恢复原始状态


131.分割回文串

🎭 题目小剧场

想象你在切蛋糕,要把它切成若干块,每块都必须是"完美对称"的(回文)。你需要找出所有可能的切法。这就是分割回文串问题!

💡 解题思路

回溯算法解法:

  1. 递归尝试从当前位置开始的所有可能分割

  2. 检查每个子串是否为回文

  3. 如果是回文,加入当前分割方案,继续递归

  4. 当到达字符串末尾时,记录完整的分割方案

  5. 回溯时撤销最后一个分割,尝试其他可能性

🐍 Python代码实现

class Solution:    def partition(self, s: str) -> List[List[str]]:        """        回溯算法 - 时间复杂度O(n×2^n),空间复杂度O(n)        """        result = []        current = []        def is_palindrome(subs):            """检查子串是否为回文"""            return subs == subs[::-1]        def backtrack(start):            """递归分割字符串"""            if start == len(s):                result.append(current.copy())                return            # 尝试从start开始的所有可能分割            for end in range(start + 1len(s) + 1):                substring = s[start:end]                # 如果是回文,继续递归                if is_palindrome(substring):                    current.append(substring)                    backtrack(end)                    current.pop()        backtrack(0)        return result

📊 复杂度分析

  • 时间复杂度:O(n×2^n) - 每个位置都有分割或不分割的选择

  • 空间复杂度:O(n) - 递归调用栈和临时数组

🌟 算法精髓

这个算法的巧妙之处在于"逐步分割"。每次尝试一个回文子串,然后递归处理剩余部分,通过回溯机制探索所有可能的分割方案。

🎯 小白友好贴士

  • is_palindrome(subs) 检查子串是否为回文

  • backtrack(start) 从start位置开始分割

  • for end in range(start + 1, len(s) + 1) 尝试所有可能的分割点

  • current.append(substring) 选择回文子串

  • current.pop() 回溯撤销选择

🔍 算法执行过程示例

= "aab"backtrack(0):├── start=0, s[0:1]="a" (回文)│   ├── current=["a"]│   ├── backtrack(1):│   │   ├── start=1, s[1:2]="a" (回文)│   │   │   ├── current=["a","a"]│   │   │   ├── backtrack(2):│   │   │   │   ├── start=2, s[2:3]="b" (回文)│   │   │   │   │   ├── current=["a","a","b"]│   │   │   │   │   ├── backtrack(3): start=3==len(s)=3 → result=[["a","a","b"]]│   │   │   │   │   ├── current=["a","a"]│   │   │   │   │   └── return│   │   │   │   └── return│   │   │   ├── current=["a"]│   │   │   └── return│   │   ├── start=1, s[1:3]="ab" (非回文) → 跳过│   │   └── return│   ├── current=[]│   └── return├── start=0, s[0:2]="aa" (回文)│   ├── current=["aa"]│   ├── backtrack(2):│   │   ├── start=2, s[2:3]="b" (回文)│   │   │   ├── current=["aa","b"]│   │   │   ├── backtrack(3): start=3==len(s)=3 → result=[["a","a","b"],["aa","b"]]│   │   │   ├── current=["aa"]│   │   │   └── return│   │   └── return│   ├── current=[]│   └── return├── start=0, s[0:3]="aab" (非回文) → 跳过└── return最终结果:[["a","a","b"],["aa","b"]] ✅

🎯 核心思想总结

  1. 逐步分割:每次尝试一个回文子串

  2. 回文检测:确保每个分割部分都是回文

  3. 递归处理:处理剩余部分的分割

  4. 回溯机制:尝试后撤销,继续其他选择


51.N皇后

🎭 题目小剧场

想象你在玩国际象棋,要在棋盘上放置n个皇后,但她们不能互相攻击。皇后可以横着、竖着、斜着移动,所以你需要确保任意两个皇后都不在同一行、同一列或同一对角线上。这就是经典的N皇后问题!

💡 解题思路

回溯算法解法:

  1. 逐行放置皇后,每行只放一个

  2. 检查当前位置是否与已放置的皇后冲突

  3. 如果不冲突,放置皇后并递归到下一行

  4. 当所有行都放置完皇后时,记录解决方案

  5. 回溯时撤销当前选择,尝试其他位置

🐍 Python代码实现

class Solution:    def solveNQueens(self, n: int) -> List[List[str]]:        """        回溯算法 - 时间复杂度O(n!),空间复杂度O(n)        """        result = []        board = [['.' for _ in range(n)] for _ in range(n)]        def is_valid(row, col):            """检查当前位置是否可以放置皇后"""            # 检查同一列            for i in range(row):                if board[i][col] == 'Q':                    return False            # 检查左上对角线            for i, j in zip(range(row-1, -1, -1), range(col-1, -1, -1)):                if board[i][j] == 'Q':                    return False            # 检查右上对角线            for i, j in zip(range(row-1, -1, -1), range(col+1, n)):                if board[i][j] == 'Q':                    return False            return True        def backtrack(row):            """递归放置皇后"""            if row == n:                # 找到解决方案,转换为字符串格式                solution = [''.join(row) for row in board]                result.append(solution)                return            # 尝试当前行的每一列            for col in range(n):                if is_valid(row, col):                    board[row][col] = 'Q'                    backtrack(row + 1)                    board[row][col] = '.'  # 回溯        backtrack(0)        return result

📊 复杂度分析

  • 时间复杂度:O(n!) - 每行的选择空间递减

  • 空间复杂度:O(n²) - 棋盘存储和递归调用栈

🌟 算法精髓

这个算法的巧妙之处在于"逐行放置"和"冲突检测"。通过每行只放一个皇后的策略,大大简化了问题,只需要检查列和对角线的冲突。

🎯 小白友好贴士

  • is_valid(row, col) 检查位置是否安全

  • for i in range(row) 检查同一列

  • zip(range(row-1, -1, -1), range(col-1, -1, -1)) 检查左上对角线

  • board[row][col] = 'Q' 放置皇后

  • board[row][col] = '.' 回溯撤销

🔍 算法执行过程示例

n = 4初始棋盘:................backtrack(0):├── row=0, 尝试col=0: (0,0)有效│   ├── board[0][0] = 'Q'│   ├── 棋盘:│   │   Q...│   │   ....│   │   ....│   │   ....│   ├── backtrack(1):│   │   ├── row=1, 尝试col=0: (1,0)冲突(同列)│   │   ├── col=1: (1,1)冲突(对角线)│   │   ├── col=2: (1,2)有效│   │   │   ├── board[1][2] = 'Q'│   │   │   ├── 棋盘:│   │   │   │   Q...│   │   │   │   ..Q.│   │   │   │   ....│   │   │   │   ....│   │   │   ├── backtrack(2):│   │   │   │   ├── row=2, 尝试col=0: (2,0)冲突(对角线)│   │   │   │   ├── col=1: (2,1)有效│   │   │   │   │   ├── board[2][1] = 'Q'│   │   │   │   │   ├── 棋盘:│   │   │   │   │   │   Q...│   │   │   │   │   │   ..Q.│   │   │   │   │   │   .Q..│   │   │   │   │   │   ....│   │   │   │   │   ├── backtrack(3):│   │   │   │   │   │   ├── row=3, 所有位置都冲突│   │   │   │   │   │   └── return│   │   │   │   │   ├── board[2][1] = '.'│   │   │   │   │   └── return│   │   │   │   ├── col=2: 冲突(同列)│   │   │   │   ├── col=3: 冲突(对角线)│   │   │   │   └── return│   │   │   ├── board[1][2] = '.'│   │   │   └── return│   │   └── return│   ├── board[0][0] = '.'│   └── return├── row=0, 尝试col=1: (0,1)有效│   ├── (类似过程,最终找到解决方案)│   └── return├── row=0, 尝试col=2: (0,2)有效│   ├── (类似过程,最终找到解决方案)│   └── return├── row=0, 尝试col=3: (0,3)有效│   ├── (类似过程,无解)│   └── return└── return最终找到的解决方案:1. .Q.. → [".Q..","...Q","Q...","..Q."]2. ..Q. → ["..Q.","Q...","...Q",".Q.."]

🎯 核心思想总结

  1. 逐行放置:每行只放一个皇后,简化问题

  2. 冲突检测:检查列和对角线冲突

  3. 回溯机制:尝试后撤销,继续其他选择

  4. 结果转换:将棋盘转换为字符串格式

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-02-09 07:18:02 HTTP/2.0 GET : https://f.mffb.com.cn/a/460260.html
  2. 运行时间 : 0.225833s [ 吞吐率:4.43req/s ] 内存消耗:4,910.29kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=5f666124f52498261a49a73f5e0c4968
  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.000721s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000928s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.002163s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.003184s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000795s ]
  6. SELECT * FROM `set` [ RunTime:0.000318s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000711s ]
  8. SELECT * FROM `article` WHERE `id` = 460260 LIMIT 1 [ RunTime:0.001953s ]
  9. UPDATE `article` SET `lasttime` = 1770592682 WHERE `id` = 460260 [ RunTime:0.002332s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000294s ]
  11. SELECT * FROM `article` WHERE `id` < 460260 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.007331s ]
  12. SELECT * FROM `article` WHERE `id` > 460260 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.020935s ]
  13. SELECT * FROM `article` WHERE `id` < 460260 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.042914s ]
  14. SELECT * FROM `article` WHERE `id` < 460260 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.012202s ]
  15. SELECT * FROM `article` WHERE `id` < 460260 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.029457s ]
0.227411s