程序
文章平均质量分 75
niji523
这个作者很懒,什么都没留下…
展开
-
求一个集合的所有子集
最先是在leedCode上看到的一个题目,走了一点弯路,使用多重for循环,结果问题很多,后来换了一种思路,代码简介而且高效。题目是这样的: Subsets: Given a set of distinct integers, S, return all possible subsets. Note:Elements in a subset must be in non-descendi原创 2013-11-27 11:32:27 · 831 阅读 · 0 评论 -
求一个集合的子集,子集元素数目固定
leetcode上的题目: 思路:和上一篇文章差不多(大体代码就是直接复制的)。只是在添加新元素到result中时,首先保证该元素长度比k小,其次保证该元素的长度不会太小,至少加上所有未处理的元素后,长度满足要求,即不小于k。最后还得将result中长度小于k的元素删掉,得出最终结果。 class Solution { public: vector > combine(原创 2013-11-27 16:57:17 · 1138 阅读 · 0 评论 -
gray code 格雷码求解问题
LeedCode OJ的一个题目: Gray Code Total Accepted: 2370 Total Submissions: 7783 My Submissions The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negat原创 2013-11-27 17:48:43 · 643 阅读 · 0 评论 -
求一个集合的排列 LeetCode OJ :Permutations
LeetCode的一道题目,题目如下: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]. 思路:假原创 2013-11-28 13:26:36 · 1043 阅读 · 0 评论