技术标签: 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.
Note:
For example, given candidate set 10,1,2,7,6,1,5
and target 8
,
A solution set is:
[1, 7]
[1, 2, 5]
[2, 6]
[1, 1, 6]
can not pass big test set.
public class Solution {
HashSet<ArrayList<Integer>> unique = new HashSet<ArrayList<Integer>>();
public ArrayList<ArrayList<Integer>> combinationSum2(int[] num, int target) {
// Start typing your Java solution below
// DO NOT write main() function
unique.clear();
ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>>();
//check input
if(num==null || num.length==0 ) return res;
ArrayList<Integer> temp = new ArrayList<Integer>();
Arrays.sort( num);
comRec(num, res, temp, target, 0, 0);
return res;
}
private void comRec(int[] num, ArrayList<ArrayList<Integer>> res, ArrayList<Integer> temp, int target, int partSum, int level){
if(level > num.length) return;
if(partSum == target ) {
ArrayList<Integer> t = new ArrayList<Integer>(temp);
if(!unique.contains(t)) {
res.add(t);
unique.add(t);
}
return;
}
for(int i=level; i<num.length; i++) {
temp.add( num[i] );
comRec(num, res, temp, target, partSum+num[i], i+1);
temp.remove( temp.size()-1);
}
}
}
文章浏览阅读3.4k次。1.工具一:slurm安装sudo apt-get install slurm (Ubuntu系统)查看网速命令slurm -i eth0 (etho为网卡名)*******************************************************************************************************xiabi_ubuntu查看网口百兆千兆
文章浏览阅读3.8k次,点赞3次,收藏30次。本文详细分析并介绍了基于opencpu方案开打bc26 NB模组的流程,主要分为开发工具套件的使用以及代码分析。_bc26
文章浏览阅读447次。C/C++Linux服务器高级架构师的课程到2022目前已经迭代到12代了,像之前小编也总结过,但是课程每期都有做一定的更新,也是为了更好的完善课程跟上目前互联网大厂的岗位技术需求,之前课程里面也包含了一些小的分支,其中就有音视频开发、Linux内核开发、DPDK、golang等等一些程序员所需要的硬核技术。今天总结分析是2022年最新的课程体系。_202212.c.c.c
文章浏览阅读1.2k次,点赞10次,收藏13次。*单片机设计介绍,基于单片机12864的出租车计价器设计。
文章浏览阅读2.7k次,点赞2次,收藏33次。使用GMap.Net控件从零开始搭建一个GIS开发小框架_greatmaps
文章浏览阅读344次。模板就是建立通用的模具,大大提高复用性。_c++泛型编程编译
文章浏览阅读335次。开发平台:i.MX6Q开发板1硬件连接作者测试can,使用的是两块 iTOP-iMX6 开发板。板子是 can 的+连接+,-连接-,如下图所示。2 canconfig工具配置首先配置工具和库文件,将压缩包“can_libs.rar”、“can_tools.zip”和 “can_libs_more.zip”解压得到“can_tools”、“can_libs”以及“”can_libs_more,拷贝解压出来的文件到 tf 卡或者 u 盘, 如下图所..._ubuntu下的设置can通信的参数
文章浏览阅读2.1k次。使用maven-jar-plugin和maven-dependency-plugin打可执行包备注:引用的第三方包放在执行目录的的lib下1.1 pop.xml <build> <plugins> <!-- 设置编译版本为1.8 --> <plugin> <groupId>org.apache...._若依框架打包出来为什么是一个 lib包一个 jar 包
文章浏览阅读2.4k次。一、简介由Google主导开发,于2011年10月公开。它的开发团队由Google Chrome浏览器V8引擎团队的领导者拉尔斯·巴克主持,目标在于成为下一代结构化Web开发语言。类似JavaScript,Dart也是一种面向对象语言,但是它采用基于类编程。Dart的设计目标应该是既对标Java,也对标JavaScript,Dart在静态语法方面和Java非常相似,如类型定义、函数声明、泛型等,而在动态特性方面又和JavaScript很像,如函数式特性、异步支持等。二、主要用途Dart有一下三个方向的_flutter dart
文章浏览阅读1.3k次,点赞47次,收藏44次。只对写操作进行加锁,加锁的方式仍然是 synchronized ,但是不是锁整个对象,而是“锁桶”,每一个链表的头节点作为锁对象,大大降低了锁冲突的概率。由于哈希表是由数组与链表或者红黑树组成的,数组的长度很长,因此相对链表的长度来说,链表的长度就很短了,所以在多线程中,对数组中的某一个链表大概率是不会冲突的,因此即使每一个链表都上锁了,这个锁也大概率是偏向锁,大概率是没有加锁和解锁的开销。扩容期间,新老数组同时存在。是一个线程安全的集合类,所有对 HashTable 的操作都是同步的,即线程安全的。_java保存线程的集合
文章浏览阅读1.4k次。图解翻译和详解深度学习GAN(含项目完整代码)_gan data flow
文章浏览阅读261次。文章版权所有 Jusin Hao(luckyfriends) ,支持原创,转载请注明@echo offcd c:\md Oracle"C:\Program Files (x86)\WinRAR\winrar.exe" x C:\win64_11gR1_database.zip C:\Oraclecopy /y c:\refhost.xml c:\Oracle\database\stage\prer..._oracle 11g windows 静默安装