摘要:        
套dfs回溯模板,模板参考:https://www.cnblogs.com/panweiwei/p/14025143.html class Solution(object): def __init__(self): # res作为返回值,设为全局变量 self.res = [] # 要得到3个a、2    阅读全文
posted @ 2020-11-23 17:00
人间烟火地三鲜
阅读(444)
评论(2)
推荐(1)
        
            
        
        
摘要:        
套dfs回溯模板,模板参考:https://www.cnblogs.com/panweiwei/p/14025143.html class Solution(object): def __init__(self): # res作为返回值,设为全局变量 self.res = [] def permut    阅读全文
posted @ 2020-11-23 16:59
人间烟火地三鲜
阅读(213)
评论(0)
推荐(1)
        
            
        
        
摘要:        
代码思路:用三个set标记当前位置所在的行、主、次对角线方向上是否合法。 class Solution(object): def solveNQueens(self, n): """ :type n: int :rtype: List[List[str]] """ # 返回值 res = [] #     阅读全文
posted @ 2020-11-23 16:57
人间烟火地三鲜
阅读(267)
评论(0)
推荐(0)
        
            
        
        
摘要:        
class Solution(object): def totalNQueens(self, n): """ :type n: int :rtype: int """ res = [] queen = [-1] * n # column = [-1] * n # dia1 = [-1] * (2 *    阅读全文
posted @ 2020-11-23 16:53
人间烟火地三鲜
阅读(198)
评论(0)
推荐(0)
        
            
        
        
摘要:        
class Solution(object): def solveNQueens(self, n): res = [] queen = [-1] * n column = set() dia1 = set() dia2 = set() self.dfs(n, res, queen, column,     阅读全文
posted @ 2020-11-23 16:50
人间烟火地三鲜
阅读(232)
评论(0)
推荐(0)
        
            
        
        
摘要:        
class Solution(object): def __init__(self): # 返回值,定义为全局变量 self.res = [] def partition(self, s): """ :type s: str :rtype: List[List[str]] """ if not s:    阅读全文
posted @ 2020-11-23 16:47
人间烟火地三鲜
阅读(206)
评论(0)
推荐(0)
        
            
        
        
摘要:        
代码一:DFS回溯 class Solution(object): # 方法一:DFS def allPathsSourceTarget(self, graph): """ :type graph: List[List[int]] :rtype: List[List[int]] """ if not    阅读全文
posted @ 2020-11-23 16:46
人间烟火地三鲜
阅读(218)
评论(0)
推荐(0)
        
            
        
        
摘要:        
还是套回溯模板,模板可参考:https://www.cnblogs.com/panweiwei/p/14025143.html class CombinationIterator(object): def __init__(self, characters, combinationLength):     阅读全文
posted @ 2020-11-23 16:44
人间烟火地三鲜
阅读(178)
评论(0)
推荐(1)
        
            
        
        
摘要:        
关于回溯,可参考:https://www.cnblogs.com/panweiwei/p/14025143.html class Solution(object): def __init__(self): self.res = [] def generateParenthesis(self, n):    阅读全文
posted @ 2020-11-23 16:42
人间烟火地三鲜
阅读(165)
评论(0)
推荐(0)
        
            
        
        
摘要:        
还是套模板,模板可参考:https://www.cnblogs.com/panweiwei/p/14025143.html class Solution(object): def __init__(self): self.res = [] def combinationSum3(self, k, n    阅读全文
posted @ 2020-11-23 16:40
人间烟火地三鲜
阅读(167)
评论(0)
推荐(0)
        
            
        
        
摘要:        
还是套模板,模板可参考:https://www.cnblogs.com/panweiwei/p/14025143.html class Solution(object): def __init__(self): self.res = [] def combine(self, n, k): """ :    阅读全文
posted @ 2020-11-23 16:38
人间烟火地三鲜
阅读(122)
评论(0)
推荐(0)
        
            
        
        
摘要:        
原串里有数字、也有字母,所以每选一个字符要加以判断,要是字母则有两种选择,数字就一种。 还是套模板,模板可参考:https://www.cnblogs.com/panweiwei/p/14025143.html class Solution(object): def __init__(self):     阅读全文
posted @ 2020-11-23 16:36
人间烟火地三鲜
阅读(239)
评论(0)
推荐(0)
        
            
        
        
摘要:        
套模板,可参考:https://www.cnblogs.com/panweiwei/p/14025143.html class Solution(object): def __init__(self): self.res = [] def subsetsWithDup(self, nums): ""    阅读全文
posted @ 2020-11-23 16:34
人间烟火地三鲜
阅读(79)
评论(0)
推荐(0)
        
            
        
        
摘要:        
套模板,可参考:https://www.cnblogs.com/panweiwei/p/14025143.html class Solution(object): def __init__(self): self.res = [] def subsets(self, nums): """ :type    阅读全文
posted @ 2020-11-23 16:33
人间烟火地三鲜
阅读(101)
评论(0)
推荐(0)
        
            
        
        
摘要:        
套模板,可参考:https://www.cnblogs.com/panweiwei/p/14025143.html class Solution(object): def __init__(self): self.res = [] def permuteUnique(self, nums): """    阅读全文
posted @ 2020-11-23 16:31
人间烟火地三鲜
阅读(73)
评论(0)
推荐(0)
        
            
        
        
摘要:        
套模板,可参考:https://www.cnblogs.com/panweiwei/p/14025143.html class Solution(object): def __init__(self): self.res = [] def permute(self, nums): """ :type    阅读全文
posted @ 2020-11-23 16:30
人间烟火地三鲜
阅读(100)
评论(0)
推荐(0)
        
            
        
        
摘要:        
可参考:https://www.cnblogs.com/panweiwei/p/14025143.html class Solution(object): def __init__(self): self.res = [] def combinationSum2(self, candidates,     阅读全文
posted @ 2020-11-23 16:28
人间烟火地三鲜
阅读(67)
评论(0)
推荐(0)
        
            
        
        
摘要:        
可参考:https://www.cnblogs.com/panweiwei/p/14025143.html class Solution(object): def __init__(self): self.res = [] def combinationSum(self, candidates, t    阅读全文
posted @ 2020-11-23 16:27
人间烟火地三鲜
阅读(94)
评论(0)
推荐(0)
        
            
        
        
摘要:        
可参考:https://www.cnblogs.com/panweiwei/p/14025143.html class Solution(object): def __init__(self): self.res = [] self.mydict = {1: "", 2: "abc", 3: "de    阅读全文
posted @ 2020-11-23 16:25
人间烟火地三鲜
阅读(312)
评论(0)
推荐(0)
        
            
        
        
摘要:        
参考:https://zhuanlan.zhihu.com/p/302415065 关于回溯 回溯是递归的“副产品”,并非高效算法,通过剪枝可以跳过非必要的搜索。 回溯算法能解决如下问题: 组合问题:N个数里面按一定规则找出k个数的集合; 排列问题:N个数按一定规则全排列,有几种排列方式; 切割问题    阅读全文
posted @ 2020-11-23 16:19
人间烟火地三鲜
阅读(418)
评论(0)
推荐(1)
        

 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号