博客
关于我
[LeetCode] 40. Combination Sum II
阅读量:249 次
发布时间:2019-03-01

本文共 642 字,大约阅读时间需要 2 分钟。

注意和39题区别,当前层值相同则跳过

回溯法

void cb2help(vector
> &res,vector
&v,int target,unsigned int i,vector
recp){ if(target<0) return; else if(target==0) { res.push_back(recp); return; } for(unsigned int k=i;k
i&&v[k]==v[k-1]) continue; recp.push_back(v[k]); cb2help(res,v,target-v[k],k+1,recp); recp.pop_back(); if(target-v[k]<0) return; }}vector
> combinationSum2(vector
& v, int target){ sort(v.begin(),v.end()); vector
> res; vector
recp; cb2help(res,v,target,0,recp); return res;}

转载地址:http://erfx.baihongyu.com/

你可能感兴趣的文章
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>