随笔分类 -  递归、回溯、分治

leetcode : 间的6个leet例子
95. Unique Binary Search Trees II
摘要:Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n. Example: Input: 3 Output: [ [1,null,3,2], 阅读全文

posted @ 2021-01-10 17:02 wsw_seu 阅读(94) 评论(0) 推荐(0)

494. 目标和(动态规划,01背包)
摘要:给定一个非负整数数组,a1, a2, ..., an, 和一个目标数,S。现在你有两个符号 + 和 -。对于数组中的任意一个整数,你都可以从 + 或 -中选择一个符号添加在前面。 返回可以使最终数组和为目标数 S 的所有添加符号的方法数。 示例: 输入:nums: [1, 1, 1, 1, 1], 阅读全文

posted @ 2020-12-20 15:14 wsw_seu 阅读(106) 评论(0) 推荐(0)

回溯问题模版(套路)https://labuladong.gitbook.io/algo/suan-fa-si-wei-xi-lie/3.1-hui-su-suan-fa-dfs-suan-fa-pian/hui-su-suan-fa-xiang-jie-xiu-ding-ban
摘要:def backtrack(路径, 选择列表): if 满足结束条件: result.add(路径) return for 选择 in 选择列表: 做选择 backtrack(路径, 选择列表) 撤销选择 参考: https://labuladong.gitbook.io/algo/suan-fa- 阅读全文

posted @ 2020-12-20 11:13 wsw_seu 阅读(306) 评论(0) 推荐(0)

486. 预测赢家(从递归到动态规划)
摘要:给定一个表示分数的非负整数数组。 玩家 1 从数组任意一端拿取一个分数,随后玩家 2 继续从剩余数组任意一端拿取分数,然后玩家 1 拿,…… 。每次一个玩家只能拿取一个分数,分数被拿取之后不再可取。直到没有剩余分数可取时游戏结束。最终获得分数总和最多的玩家获胜。 给定一个表示分数的数组,预测玩家1是 阅读全文

posted @ 2020-12-20 10:22 wsw_seu 阅读(167) 评论(0) 推荐(0)

395. Longest Substring with At Least K Repeating Characters
摘要:Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than  阅读全文

posted @ 2020-11-01 11:48 wsw_seu 阅读(63) 评论(0) 推荐(0)

37 Sudoku Solver
摘要:Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy all of the following rules: Each of the digits 1-9 阅读全文

posted @ 2020-10-19 22:19 wsw_seu 阅读(67) 评论(0) 推荐(0)

36. Valid Sudoku
摘要:Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the dig 阅读全文

posted @ 2020-10-18 16:12 wsw_seu 阅读(107) 评论(0) 推荐(0)

分治 315. 计算右侧小于当前元素的个数
摘要:给定一个整数数组 nums,按要求返回一个新数组 counts。数组 counts 有该性质: counts[i] 的值是 nums[i] 右侧小于 nums[i] 的元素的数量。 示例: 输入: [5,2,6,1]输出: [2,1,1,0] 解释:5 的右侧有 2 个更小的元素 (2 和 1).2 阅读全文

posted @ 2020-07-08 21:43 wsw_seu 阅读(192) 评论(0) 推荐(0)

40. 组合总和 II
摘要:https://leetcode-cn.com/problems/combination-sum-ii/ 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 candidates 中的每个数字在每个组合中只能使用 阅读全文

posted @ 2020-06-28 15:50 wsw_seu 阅读(186) 评论(0) 推荐(0)

39. 组合总和
摘要:https://leetcode-cn.com/problems/combination-sum/ 给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 candidates 中的数字可以无限制重复被选 阅读全文

posted @ 2020-06-28 15:18 wsw_seu 阅读(129) 评论(0) 推荐(0)

90. 子集 II
摘要:https://leetcode-cn.com/problems/subsets-ii/ 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。 说明:解集不能包含重复的子集。 示例: 输入: [1,2,2]输出:[ [2], [1], [1,2,2], [2,2], [1 阅读全文

posted @ 2020-06-28 14:59 wsw_seu 阅读(121) 评论(0) 推荐(0)

78. 子集
摘要:https://leetcode-cn.com/problems/subsets/submissions/ 给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。 说明:解集不能包含重复的子集。 示例: 输入: nums = [1,2,3]输出:[ [3], [1], [2], 阅读全文

posted @ 2020-06-28 11:22 wsw_seu 阅读(178) 评论(0) 推荐(0)

导航