![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode之backtracking
文章平均质量分 71
Shawn_Redemption
这个作者很懒,什么都没留下…
展开
-
【Leetcode】Subsets II (Backtracking)
public ArrayList> subsetsWithDup(int[] num) { ArrayList> result = new ArrayList>(); result.add(new ArrayList()); if (num == null || num.length == 0) return result; Arrays.sort(num); int s原创 2014-11-10 02:52:41 · 357 阅读 · 0 评论 -
【Leetcode】Permutations II (Backtracking)
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].原创 2014-11-05 10:49:35 · 296 阅读 · 0 评论 -
【Leetcode】Generate Parentheses (Backtracking)
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()原创 2014-11-06 04:04:11 · 440 阅读 · 0 评论 -
【Leetcode】Permutations (Backtracking)
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].原创 2014-11-05 09:27:34 · 313 阅读 · 0 评论 -
【Leetcode】Combination Sum II (Backtracking)
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 combina原创 2014-11-05 08:05:31 · 313 阅读 · 0 评论 -
【Leetcode】Combination Sum (Backtracking)
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb原创 2014-11-04 11:24:44 · 314 阅读 · 0 评论 -
【Leetcode】Combinations (Backtracking)
这是一道经典的NP问题,采用回朔法i从1开始,先加入1,再加入2 temp=[1,2]然后去掉2 加3 temp=[1,3]然后去掉3 加4 temp=[1,4]然后去掉4 i=5不合法了 结束for循环然后去掉1返回到i=1,然后i++原创 2014-11-04 08:35:23 · 571 阅读 · 0 评论 -
【Leetcode】N-Queens (Backtracking)
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.原创 2014-11-06 10:39:42 · 392 阅读 · 0 评论 -
【Leetcode】Word Ladder II (Backtracking)
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be changed at a timeEach intermediate word must exi原创 2014-11-14 01:34:00 · 548 阅读 · 0 评论 -
【Leetcode】Subsets (Backtracking)
Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For exa原创 2014-11-10 00:46:57 · 405 阅读 · 0 评论 -
【Leetcode】N-Queens II (Backtracking)
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.原创 2014-11-06 08:09:03 · 378 阅读 · 0 评论