![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
回溯/递归
文章平均质量分 54
纸上得来终深浅
这个作者很懒,什么都没留下…
展开
-
Leetcode 37 解数独 --回溯法的返回值与分支选择问题
1. 方法一**class Solution { boolean[][] usedRow; boolean[][] usedCol; boolean[][] usedBoxed; public Solution() { this.usedRow = new boolean[10][10]; this.usedCol = new boolean[10][10]; t原创 2021-10-10 18:38:49 · 108 阅读 · 0 评论 -
Leetcode139 从回溯到记忆化到动态规划
//给定一个非空字符串 s 和一个包含非空单词的列表 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。//// 说明:////// 拆分时可以重复使用字典中的单词。// 你可以假设字典中没有重复的单词。////// 示例 1://// 输入: s = “leetcode”, wordDict = [“leet”, “code”]//输出: true//解释: 返回 true 因为 “leetcode” 可以被拆分成 “leet code”。////原创 2021-10-10 12:17:53 · 132 阅读 · 0 评论 -
LeetCode回溯算法
1. leetcode 77组合//给定两个整数 n 和 k,返回范围 [1, n] 中所有可能的 k 个数的组合。模板一,利用used数组List<List<Integer>> ans = new LinkedList<>(); public List<List<Integer>> combine(int n, int k) { backTrace(n, k, 0, new LinkedList原创 2021-09-20 17:25:24 · 85 阅读 · 0 评论 -
LeetCode 638大礼包
题目//在 LeetCode 商店中, 有 n 件在售的物品。每件物品都有对应的价格。然而,也有一些大礼包,每个大礼包以优惠的价格捆绑销售一组物品。//// 给你一个整数数组 price 表示物品价格,其中 price[i] 是第 i 件物品的价格。另有一个整数数组 needs 表示购物清单,其中 needs[//i] 是需要购买第 i 件物品的数量。//// 还有一个数组 special 表示大礼包,special[i] 的长度为 n + 1 ,其中 special[i][j] 表示第 i 个原创 2021-09-12 23:21:17 · 204 阅读 · 0 评论