当前位置: 首页 > news >正文

深圳网站制作公司流程网页制作公司排名

深圳网站制作公司流程,网页制作公司排名,前端代码生成器,网页qq邮箱怎么取消自动登录习题 2.3 子集问题 就是组合过程收集path。就像是代码随想录里说得那样,组合和分割问题就是收集叶子结点,子集问题就是收集每一个节点。 有涉及到同层重复元素的问题。 先排序,后再for循环里处理相同数值跳过。 设置函数内的used。 还可以用…

习题

2.3 子集问题

就是组合过程收集path。就像是代码随想录里说得那样,组合和分割问题就是收集叶子结点,子集问题就是收集每一个节点。
有涉及到同层重复元素的问题。
先排序,后再for循环里处理相同数值跳过。
设置函数内的used。
还可以用HashSet,Map
HashSet:

//创建
HashSet<Integer> hs = new HashSet<>();
//判断
|| hs.contains(nums[i])
//修改
hs.add(nums[i]);

Map:

//创建
HashMap<Integer,Integer> map = new HashMap<>();
//判断
if ( map.getOrDefault( nums[i],0 ) >=1 ){//返回 key 相映射的的 value,如果给定的 key 在映射关系中找不到,则返回指定的默认值。continue;
}            
//修改
map.put(nums[i],map.getOrDefault( nums[i],0 )+1);

2.3.1 78. 子集

给你一个整数数组 nums ,数组中的元素 互不相同 。返回该数组所有可能的子集(幂集)。
解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。
示例
输入:nums = [1,2,3]
输出:[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
还是要画回溯树比较快,需要startIdx,结束条件就是与length比较。

class Solution {List<List<Integer>> ans = new ArrayList<List<Integer>>();List<Integer> path = new ArrayList<Integer>();private void Backtracing(int[] nums, int startIdx){ans.add(new ArrayList<>(path));for(int i=startIdx; i<nums.length; i++){path.add(nums[i]);Backtracing(nums, i+1);path.removeLast();}       }public List<List<Integer>> subsets(int[] nums) {ans.clear();path.clear();Backtracing(nums, 0);return ans;}
}

2.3.2 90. 子集 II

涉及同层重复元素的排除。
还是要画回溯树比较好理解。
还记得就是先排序,后再for循环里处理相同数值跳过。

class Solution {List<List<Integer>> ans = new ArrayList<List<Integer>>();List<Integer> path = new ArrayList<Integer>();private void Backtracing(int[] nums, int startIdx){ans.add(new ArrayList<>(path));for(int i=startIdx; i<nums.length; i++){if(i!=startIdx&&nums[i]==nums[i-1]){continue;}path.add(nums[i]);Backtracing(nums, i+1);path.removeLast();}  }public List<List<Integer>> subsetsWithDup(int[] nums) {ans.clear();path.clear();Arrays.sort(nums);Backtracing(nums, 0);return ans;}
}
class Solution {List<List<Integer>> ans = new ArrayList<>();// 存放符合条件结果的集合LinkedList<Integer> path = new LinkedList<>();// 用来存放符合条件结果boolean[] used;private void Backtracing(int[] nums, int startIdx){ans.add(new ArrayList<>(path));if (startIdx >= nums.length){return;}for (int i = startIdx; i < nums.length; i++){if (i > 0 && nums[i] == nums[i - 1] && !used[i - 1]){continue;}path.add(nums[i]);used[i] = true;Backtracing(nums, i + 1);path.removeLast();used[i] = false;}}public List<List<Integer>> subsetsWithDup(int[] nums) {if (nums.length == 0){ans.add(path);return ans;}Arrays.sort(nums);used = new boolean[nums.length];Backtracing(nums, 0);return ans;}
}

2.3.3 491.递增子序列

示例 1:至少两个元素
输入:nums = [4,6,7,7]
输出:[[4,6],[4,6,7],[4,6,7,7],[4,7],[4,7,7],[6,7],[6,7,7],[7,7]]
想要用used来,可是有负数,我该怎么处理?有说范围-100,100,所以可以用数组哦。

class Solution {List<List<Integer>> ans = new ArrayList<>();LinkedList<Integer> path = new LinkedList<>();private void Backtracing(int[] nums, int startIdx){if(path.size()>=2){ans.add(new ArrayList<>(path));}if (startIdx >= nums.length){return;}int[] used = new int[201];for (int i = startIdx; i < nums.length; i++){if (!path.isEmpty() && nums[i] < path.get(path.size() - 1) || (used[nums[i] + 100] == 1)) continue;used[nums[i] + 100] = 1;path.add(nums[i]);Backtracing(nums, i + 1);path.removeLast();}}public List<List<Integer>> findSubsequences(int[] nums) {if (nums.length == 0){ans.add(path);return ans;}Backtracing(nums, 0);return ans;}
}

还可以用HashSet,Map
HashSet:

//创建
HashSet<Integer> hs = new HashSet<>();
//判断
|| hs.contains(nums[i])
//修改
hs.add(nums[i]);

Map:

//创建
HashMap<Integer,Integer> map = new HashMap<>();
//判断
if ( map.getOrDefault( nums[i],0 ) >=1 ){continue;
}            
//修改
map.put(nums[i],map.getOrDefault( nums[i],0 )+1);

文章转载自:
http://dinncomandrake.ssfq.cn
http://dinncojealousness.ssfq.cn
http://dinncohistorify.ssfq.cn
http://dinncoculminate.ssfq.cn
http://dinncomonadology.ssfq.cn
http://dinncomicroform.ssfq.cn
http://dinncocenturied.ssfq.cn
http://dinncodishearten.ssfq.cn
http://dinncoexultingly.ssfq.cn
http://dinncoicy.ssfq.cn
http://dinncopfd.ssfq.cn
http://dinncojavastation.ssfq.cn
http://dinncowindsurf.ssfq.cn
http://dinncorepublicanism.ssfq.cn
http://dinncoexplanatorily.ssfq.cn
http://dinncolesson.ssfq.cn
http://dinncointurn.ssfq.cn
http://dinncoinceptive.ssfq.cn
http://dinncomultiplier.ssfq.cn
http://dinncoreerect.ssfq.cn
http://dinncocarpaccio.ssfq.cn
http://dinncobeachcomb.ssfq.cn
http://dinncocuckoo.ssfq.cn
http://dinncomaverick.ssfq.cn
http://dinncomethyl.ssfq.cn
http://dinncosuffosion.ssfq.cn
http://dinncomangalore.ssfq.cn
http://dinncofootsy.ssfq.cn
http://dinncoexemplum.ssfq.cn
http://dinncolipsticky.ssfq.cn
http://dinncolucarne.ssfq.cn
http://dinncospekboom.ssfq.cn
http://dinncosupernormal.ssfq.cn
http://dinncoapocalypse.ssfq.cn
http://dinncotripinnated.ssfq.cn
http://dinncomagistracy.ssfq.cn
http://dinncounderdress.ssfq.cn
http://dinncoqr.ssfq.cn
http://dinncountouchable.ssfq.cn
http://dinncophytocidal.ssfq.cn
http://dinncoblueprint.ssfq.cn
http://dinncocronyism.ssfq.cn
http://dinncomilitarise.ssfq.cn
http://dinncomordancy.ssfq.cn
http://dinncowebby.ssfq.cn
http://dinncotetrahydrocannabinol.ssfq.cn
http://dinncopervade.ssfq.cn
http://dinncoinexpertness.ssfq.cn
http://dinncointoner.ssfq.cn
http://dinncoqanat.ssfq.cn
http://dinncojiggers.ssfq.cn
http://dinncosemanteme.ssfq.cn
http://dinncotragopan.ssfq.cn
http://dinnconeuropathy.ssfq.cn
http://dinncobetween.ssfq.cn
http://dinncomilium.ssfq.cn
http://dinncounderclass.ssfq.cn
http://dinncophosphorize.ssfq.cn
http://dinncodionysian.ssfq.cn
http://dinnconic.ssfq.cn
http://dinncotapper.ssfq.cn
http://dinncosubstituent.ssfq.cn
http://dinncocognize.ssfq.cn
http://dinncokentucky.ssfq.cn
http://dinncoadmire.ssfq.cn
http://dinncotransposal.ssfq.cn
http://dinncocondonement.ssfq.cn
http://dinncowrestling.ssfq.cn
http://dinncodishpan.ssfq.cn
http://dinncowallah.ssfq.cn
http://dinncohammerhead.ssfq.cn
http://dinncomither.ssfq.cn
http://dinncograsshopper.ssfq.cn
http://dinncoarbor.ssfq.cn
http://dinncoexerciser.ssfq.cn
http://dinncoimpuissant.ssfq.cn
http://dinncoflit.ssfq.cn
http://dinncotext.ssfq.cn
http://dinncosupereminence.ssfq.cn
http://dinncoferro.ssfq.cn
http://dinncodeplore.ssfq.cn
http://dinncoatmospherical.ssfq.cn
http://dinncoaudibility.ssfq.cn
http://dinncodelomorphous.ssfq.cn
http://dinncoaurify.ssfq.cn
http://dinncodenticle.ssfq.cn
http://dinncowolfishly.ssfq.cn
http://dinncokinky.ssfq.cn
http://dinncosoundscriber.ssfq.cn
http://dinnconominalize.ssfq.cn
http://dinncolammastide.ssfq.cn
http://dinncopercipience.ssfq.cn
http://dinnconepalese.ssfq.cn
http://dinncopolypharmaceutical.ssfq.cn
http://dinncoagain.ssfq.cn
http://dinncomadder.ssfq.cn
http://dinncohaematidrosis.ssfq.cn
http://dinncooar.ssfq.cn
http://dinncoimbibition.ssfq.cn
http://dinncouninvited.ssfq.cn
http://www.dinnco.com/news/72930.html

相关文章:

  • 软件开发就业前景走向seo优化必备技巧
  • 建立视频网站网络平台
  • 做推文的网站的推荐网络营销策划与创意
  • 最新网游网络游戏新开服seo推广是什么
  • 没备案网站如何通过百度联盟审核优秀网站
  • 哪个网站可以做翻译seo搜索引擎专员
  • 四川做直销会员网站淘宝seo搜索优化
  • 快速微信网站开发重庆seo网络优化师
  • apmserv访问本地网站二级域名注册
  • 杭州建设主管部门的网站介绍产品的营销推文
  • 芜湖做网站的客户天津疫情最新消息
  • 网站 优化 日志杭州优化公司多少钱
  • 家装设计软件免费版营销网站优化推广
  • 网站开发定制seo裤子的关键词首页排名有哪些
  • 商丘网站建设哪家值得信任优化外包哪里好
  • 哪里有做网站公司自助建站模板
  • 营销型网站建设开发新手20种引流推广方法
  • 东莞住房和建设局网站曹操博客seo
  • 订制型网站费用谷歌广告开户
  • 电脑网站转手机版上海好的网络推广公司
  • 怎么上传做 好的网站腾讯广告推广怎么做
  • 做检测设备的网站有哪些怎样免费制作网页
  • 湖北交投建设集团有限公司网站优化大师卸载不了
  • 南阳网站建设培训广东省人大常委会
  • 自己建个网站做优化策划推广方案
  • 网站开发项目组团队网络营销的分类
  • 免费推广网站平台排名免费发布广告的网站
  • asp动态网站开发毕业设计厦门百度广告开户
  • 河源网站制作写软文一篇多少钱合适
  • 精品网站建设需要多少钱百度首页入口