摘要: 17. 电话号码的字母组合 - 力扣(LeetCode) 思路 回溯法 func letterCombinations(digits string) []string { if len(digits) == 0 || len(digits) > 4 { return nil } strMap := 阅读全文
posted @ 2022-05-09 22:54 SoutherLea 阅读(26) 评论(0) 推荐(0) 编辑
摘要: 22. 括号生成 - 力扣(LeetCode) 思路 深度优先遍历 func generateParenthesis(n int) []string { res := make([]string, 0) var dfs func(temp string, leftCount int, rightCo 阅读全文
posted @ 2022-05-09 21:42 SoutherLea 阅读(13) 评论(0) 推荐(0) 编辑
摘要: 39. 组合总和 - 力扣(LeetCode) 思路 回溯 还是以递归全排列+剪枝来搞,套用回溯模板。 var res [][]int func combinationSum(candidates []int, target int) [][]int { res = make([][]int, 0) 阅读全文
posted @ 2022-05-09 21:04 SoutherLea 阅读(24) 评论(0) 推荐(0) 编辑
摘要: 46. 全排列 - 力扣(LeetCode) 思路 回溯法 var res [][]int func permute(nums []int) [][]int { res = make([][]int, 0) backTracking([]int{}, nums, len(nums)) return 阅读全文
posted @ 2022-05-09 20:27 SoutherLea 阅读(21) 评论(0) 推荐(0) 编辑
摘要: 78. 子集 - 力扣(LeetCode) 思路 回溯法 使用回溯模板 1. 无返回值的递归函数 2.通常命名为backtracking 3. 参数依据题意来决定 4. if 终止条件{ 收集结果 return } for (集合内元素集){ 处理节点(将节点存到结果数组中) 递归函数 进行回溯操作 阅读全文
posted @ 2022-05-09 19:32 SoutherLea 阅读(12) 评论(0) 推荐(0) 编辑