LeetCode之回溯
黄焖鸡米饭啊
嗯。
展开
-
Regular_Expression_Matching
题目描述:Implement regular expression matching with support for '.' and '*'. '.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input s原创 2018-01-18 11:28:30 · 305 阅读 · 0 评论 -
组合
题目: 给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合。 示例: 输入:n = 4, k = 2 输出: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] 思路:从n个数中取k个数,首先创建一个大小为k的数组tmp,之后依次向tmp[0]到tmp[k-1]赋值,每次赋值完一遍就保存一次tmp,...原创 2019-09-24 11:06:11 · 123 阅读 · 0 评论 -
全排列 II
题目: 给定一个可包含重复数字的序列,返回所有不重复的全排列。 示例: 输入: [1,1,2] 输出: [ [1,1,2], [1,2,1], [2,1,1] ] 思路:在全排列的基础上加入一个去重判断。如果待交换的数字和被换位置的数字相同则跳过不交换,因为如果交换了那么就会产生重复序列。 //结果集 vector<vector<int>> res...原创 2019-09-22 22:50:39 · 259 阅读 · 0 评论 -
组合总和 II
题目: 给定一个数组candidates和一个目标数target,找出candidates中所有可以使数字和为target的组合。 candidates中的每个数字在每个组合中只能使用一次。 说明: 所有数字(包括目标数)都是正整数。 解集不能包含重复的组合。 示例1: 输入: candidates =[10,1,2,7,6,1,5], target =8, 所...原创 2019-09-22 21:00:18 · 88 阅读 · 0 评论 -
组合总和
题目: 给定一个无重复元素的数组candidates和一个目标数target,找出candidates中所有可以使数字和为target的组合。candidates中的数字可以无限制重复被选取。 说明: 所有数字(包括target)都是正整数。 解集不能包含重复的组合。 示例1: 输入: candidates = [2,3,6,7], target = 7, 所求解...原创 2019-09-16 19:05:49 · 115 阅读 · 0 评论 -
Letter Case Permutation
题目描述: https://leetcode-cn.com/problems/letter-case-permutation/ 思路:将字符串的转化看作一个二叉树的遍历(如下图),但要注意一点,在数字节点上,不能进行分支,否则会产生重复的情况。 #include<...原创 2019-01-14 21:16:23 · 207 阅读 · 0 评论 -
Binary Watch
题目描述: https://leetcode-cn.com/problems/binary-watch/ 题目过长,就不多描述了,直接点链接即可。 思路:列举m个小时灯亮,n个分钟灯亮的情况下的各种小时和分钟的值,并且排列组合即可。(m+n==num) #include<cstdio> #include<iostream> #include<vector&g...原创 2019-01-13 22:09:06 · 184 阅读 · 0 评论 -
分解质因数
题目描述: 将一个正整数分解质因数,例如90=2x3x3x5. 思路:判断一个因数是否为质数,然后排列组合这些质数。 #include<cstdio> #include<stdlib.h> //用来记录每个质因数的个数 int *count; //判断一个数是否为质数 bool check(int num) { for(int i=2;i<num;i+...原创 2018-10-01 22:21:45 · 273 阅读 · 0 评论 -
Permutation Sequence
题目描述:The set [1,2,3,...,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, we get the following sequence for n = 3: "123" "132" "213" "...原创 2018-07-13 18:46:32 · 127 阅读 · 0 评论 -
Additive Number
题目描述:Additive number is a string whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in th...原创 2018-07-07 13:15:20 · 229 阅读 · 0 评论 -
Split Array into Fibonacci Sequence
题目描述: Given a string S of digits,such as S = "123456579",we can split it into a Fibonacci-likesequence [123, 456, 579]. Formally, a Fibonacci-like sequence is a list F of non-negative integers such ...原创 2018-07-24 23:02:51 · 318 阅读 · 0 评论 -
Word Search
题目描述:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or verticall...原创 2018-07-11 12:34:44 · 215 阅读 · 0 评论 -
Combination_Sum
题目描述: Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may b原创 2017-09-07 11:16:57 · 257 阅读 · 0 评论 -
Combination_Sum_II
题目描述: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once in the原创 2017-09-07 12:03:34 · 209 阅读 · 0 评论 -
子集 II
题目: 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。 说明:解集不能包含重复的子集。 示例: 输入: [1,2,2] 输出: [ [2], [1], [1,2,2], [2,2], [1,2], [] ] 思路:从数组nums中取子集,子集长度从0到len(nums长度)。在取不同长度子集时都对应一个长度为k(0-len)的数组...原创 2019-09-25 11:07:37 · 302 阅读 · 0 评论