-
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. 题意:1..9个数,从中选择k个,和为n,要求输出所有满足题意的集合。 思路:枚举子集,根据sum和集合元素个数剪枝即可。 /* *********************************************** Author :111qqz Created Time …
Read More -
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. 思路:就是枚举子集,根据集合的大小剪枝。。。最后只要集合大小为k的集合 /* *********************************************** Author :111qqz Created Time :2017年04月13日 星期四 15时25分37秒 File Name :77.cpp ************************************************ */ class Solution { …
Read More -
* Total Accepted: **106670** * Total Submissions: **329718** * Difficulty: **Medium** * Contributor: **LeetCode** 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 combination. …
Read More -
Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets. For example, If nums = [1,2,2], a solution is: [ [2], [1], [1,2,2], [2,2], [1,2], [] ] 思路: 复习(?)一下 枚举子集的三种写法 (还有种更飘逸的...先不写了orz 这道题我用位向量法A的。。 /* …
Read More