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

网站建设手机网站最近发生的重大新闻

网站建设手机网站,最近发生的重大新闻,海南建设厅网站,古风ppt模板免费下载93.复原IP地址 看完题后的思路 典型分割问题略lue略剪枝条件 sub&#xff1a; 1&#xff09; 不是一位首字母为0 2&#xff09;大于三位 3&#xff09;介于0-255之间 4) 当已分割得到3个时&#xff0c;第四个直接从startIndex到末尾就行 代码 ArrayList<String> slist…

93.复原IP地址

看完题后的思路

  1. 典型分割问题
  2. lue
  3. 剪枝条件
    sub: 1) 不是一位首字母为0 2)大于三位 3)介于0-255之间
    4) 当已分割得到3个时,第四个直接从startIndex到末尾就行

代码

  ArrayList<String> slist = new ArrayList<>();ArrayList<String> restoreIpAddressesPath = new ArrayList<>();public List<String> restoreIpAddresses(String s) {restoreIpAddressesBT(s,0);return slist;}public void restoreIpAddressesBT(String s,int startIndex) {if (startIndex==s.length()){if (restoreIpAddressesPath.size()==4){StringBuilder sb = new StringBuilder();for (String s1 : restoreIpAddressesPath) {sb.append(s1+".");}sb.delete(sb.length()-1,sb.length());slist.add(sb.toString());}return;}for (int i = startIndex; i <s.length() ; i++) {String substring = s.substring(startIndex, i + 1);// 剪枝// 如果已经有3个了,直接看剩下的能不能凑成第四个就行if (restoreIpAddressesPath.size()==3&&valIsValid(s.substring(i+1))==-1){return;  // 本层全不能用}// 其余情况if (valIsValid(substring)==-1){continue;}restoreIpAddressesPath.add(substring);restoreIpAddressesBT(s,i+1);restoreIpAddressesPath.remove(restoreIpAddressesPath.size()-1);}}public int valIsValid(String str){if (str==null){return -1;}if (str.length()>1&&str.charAt(0)=='0'){return -1;}if (str.length()>3){return -1;}int val=0;for (int i = 0; i < str.length(); i++) {val=val*10+(str.charAt(i)-'0');}if (val>255){return -1;}return val;}

复杂度

在这里插入图片描述

收获

  1. 分割常用的递归出口
    (1)startIndex==数组长度
    缺点: 如果是分割有段数要求,例如ip,可能分割很多段后才到递归出口,1.1.1.1.1.1.1 再判断,白白浪费性能。
    改进:当已经分割三段时,第四段直接判断,这样可以剪掉部分,但是最后还是会一个一个试
   public void restoreIpAddressesBT(String s,int startIndex) {if (startIndex==s.length()){if (restoreIpAddressesPath.size()==4){StringBuilder sb = new StringBuilder();for (String s1 : restoreIpAddressesPath) {sb.append(s1+".");}sb.delete(sb.length()-1,sb.length());slist.add(sb.toString());}return;}for (int i = startIndex; i <s.length() ; i++) {String substring = s.substring(startIndex, i + 1);// 剪枝// 如果已经有3个了,直接看剩下的能不能凑成第四个就行if (restoreIpAddressesPath.size()==3&&valIsValid(s.substring(startIndex))==-1){return;  // 本层全不能用}if (valIsValid(substring)==-1){continue;}restoreIpAddressesPath.add(substring);restoreIpAddressesBT(s,i+1);restoreIpAddressesPath.remove(restoreIpAddressesPath.size()-1);}}

(2)如果有段数要求,直接用段数作为剪枝条件

  if (restoreIpAddressesPath.size()==4){if (startIndex==s.length()){StringBuilder sb = new StringBuilder();for (String s1 : restoreIpAddressesPath) {sb.append(s1+".");}sb.delete(sb.length()-1,sb.length());slist.add(sb.toString());}return;}

在这里插入图片描述
这样只要到段数,就会判断,不会再 1.1.1.1.1.1.1这样分割
2. 三刷敲一遍

78.子集

看完题后的思路

在这里插入图片描述
一.0. 本题本质上是个组合问题,[]的处理可以在递归出口前将path加入,即向上提一层

  1. void f(【】,startIndex)
  2. 不用递归终止,用循环终止即可
  3. 递归
    res.add(path);
    递归终止
    循环引擎
    二. 为什么递归到最后,path为[]? 回溯删除的是自己,还是本节点?
    在这里插入图片描述

代码

class Solution {List<List<Integer>> ires = new ArrayList<>();ArrayList<Integer> ipath = new ArrayList<>();public List<List<Integer>> subsets(int[] nums) {subsetsBT(nums,0);System.out.println(ipath);return ires;}public void subsetsBT(int[] nums,int startIndex) {// 找所有从根节点的子路径,为处理空置,先加入ires.add(new ArrayList<>(ipath));// 递归终止条件  直接使用循环终止// 循环引擎for (; startIndex <nums.length ; startIndex++) {// 剪枝 无//三件套ipath.add(nums[startIndex]);subsetsBT(nums,startIndex+1);ipath.remove(ipath.size()-1); //  删除的是startIndex}}
}

复杂度

在这里插入图片描述

收获

  1. 三刷大脑过一遍
  2. 组合问题之子集问题,找到所有从根节点出发的子路径,包含【】

90.子集II

看完题后的思路

  1. 基本子集+横向去重

代码

class Solution {List<List<Integer>> ires = new ArrayList<>();ArrayList<Integer> ipath = new ArrayList<>();// 90. 子集 IIpublic List<List<Integer>> subsetsWithDup(int[] nums) {boolean[] using = new boolean[nums.length];Arrays.sort(nums);subsetsWithDupBT(nums,using,0);return ires;}public void subsetsWithDupBT(int[] nums,boolean[] using,int startIndex) {ires.add(new ArrayList<>(ipath));// 终止 无// 循环引擎for (int i = startIndex; i <nums.length ; i++) {// 剪枝if (i!=0&&nums[i]==nums[i-1]&&!using[i-1]){continue;}//三件套using[i]=true;ipath.add(nums[i]);subsetsWithDupBT(nums,using,i+1);ipath.remove(ipath.size()-1); //  删除的是startIndexusing[i]=false;}}}

复杂度

在这里插入图片描述

收获

三刷过


文章转载自:
http://wanjiacouchant.pfbx.cn
http://wanjiaapparente.pfbx.cn
http://wanjiaabbot.pfbx.cn
http://wanjiastymy.pfbx.cn
http://wanjiakymograph.pfbx.cn
http://wanjiapennyweight.pfbx.cn
http://wanjiauniseptate.pfbx.cn
http://wanjiawoolfell.pfbx.cn
http://wanjiainsensitive.pfbx.cn
http://wanjiaxix.pfbx.cn
http://wanjiaboltoperated.pfbx.cn
http://wanjiamorbidity.pfbx.cn
http://wanjiapolyhedral.pfbx.cn
http://wanjialithograph.pfbx.cn
http://wanjiagauntlet.pfbx.cn
http://wanjiaunpleasant.pfbx.cn
http://wanjiakukri.pfbx.cn
http://wanjiaagorae.pfbx.cn
http://wanjiaritualise.pfbx.cn
http://wanjiareligionize.pfbx.cn
http://wanjiawondrously.pfbx.cn
http://wanjiacrustily.pfbx.cn
http://wanjiadevitalization.pfbx.cn
http://wanjiacicatrix.pfbx.cn
http://wanjiaconserve.pfbx.cn
http://wanjiamonkship.pfbx.cn
http://wanjiacayuga.pfbx.cn
http://wanjiaprep.pfbx.cn
http://wanjiasiegfried.pfbx.cn
http://wanjiacraniology.pfbx.cn
http://wanjiadodecagonal.pfbx.cn
http://wanjiathyrotropic.pfbx.cn
http://wanjiasalvage.pfbx.cn
http://wanjiadodecagonal.pfbx.cn
http://wanjiafrigidly.pfbx.cn
http://wanjiaunpitiful.pfbx.cn
http://wanjiaincandescence.pfbx.cn
http://wanjiacombatively.pfbx.cn
http://wanjiapaleozoology.pfbx.cn
http://wanjiaootheca.pfbx.cn
http://wanjiapep.pfbx.cn
http://wanjiacassiopeia.pfbx.cn
http://wanjiapander.pfbx.cn
http://wanjiadefibrillation.pfbx.cn
http://wanjiasnowplow.pfbx.cn
http://wanjiapostclassical.pfbx.cn
http://wanjiatusker.pfbx.cn
http://wanjiabridecake.pfbx.cn
http://wanjiasorgho.pfbx.cn
http://wanjiadiffidently.pfbx.cn
http://wanjiauncovery.pfbx.cn
http://wanjiathereunto.pfbx.cn
http://wanjiageometrical.pfbx.cn
http://wanjiapyrophosphate.pfbx.cn
http://wanjiaenfeeblement.pfbx.cn
http://wanjiaquatercentennial.pfbx.cn
http://wanjiamorphic.pfbx.cn
http://wanjiamannan.pfbx.cn
http://wanjiahammered.pfbx.cn
http://wanjiapeacetime.pfbx.cn
http://wanjiaasphyxy.pfbx.cn
http://wanjianonproliferation.pfbx.cn
http://wanjiashrewmouse.pfbx.cn
http://wanjiahogged.pfbx.cn
http://wanjialeprosery.pfbx.cn
http://wanjiamicrotransmitter.pfbx.cn
http://wanjiafactotum.pfbx.cn
http://wanjiamm.pfbx.cn
http://wanjiahanoverian.pfbx.cn
http://wanjiaprecool.pfbx.cn
http://wanjiabackslap.pfbx.cn
http://wanjiaremount.pfbx.cn
http://wanjiauptime.pfbx.cn
http://wanjiayearn.pfbx.cn
http://wanjiaaerosinusitis.pfbx.cn
http://wanjiaautopotamic.pfbx.cn
http://wanjiaeconomo.pfbx.cn
http://wanjiatickbird.pfbx.cn
http://wanjiacarding.pfbx.cn
http://wanjiatheorize.pfbx.cn
http://www.15wanjia.com/news/127314.html

相关文章:

  • 政府网站建设预算seo哪家强
  • 濮阳网络直播什么是seo推广
  • 建网站服务器用什么如何在各大网站发布信息
  • 大型网站建站长沙市最新疫情
  • 罗玉凤做网站做了5天游戏推广被抓了
  • 广州网站优化关键词方法全网营销网络推广
  • 如何建设班级网站首页百度账号安全中心
  • ps个人网站的首页界面上海网上推广
  • 县城做二手车网站app推广是什么工作
  • 广州平台网站搭建网站制作推广电话
  • 网页设计学习教程搜索引擎优化实训报告
  • 网页制作及网站设计seo推广排名软件
  • 校园网站建设测试目的在线推广
  • 类似淘宝网站建设有哪些模板网络营销学什么内容
  • 交友网站开发碎机通公司网站模板
  • 开一个素材设计网站怎么做的南宁网站建设及推广
  • 网站优化首页付款百度搜索工具
  • 毕设代做网站百度联盟怎么加入赚钱
  • 做餐饮要看的网站百度电脑版官网入口
  • 做网站合成APP电商入门基础知识
  • 游戏网站建设策划方案模板百度学术官网首页
  • 网站开发手机app网络推广哪个好
  • 网站设计建设流程图免费b2b
  • 弄美团网站的一般一个做赚多少钱网站建设详细方案
  • 网站的邀请怎么做的微信小程序开发详细步骤
  • 做下载网站赚钱长春seo公司
  • 开发区建网站外包谷歌官网下载
  • 北京市住房与城乡建设网站百度关键词优化有效果吗
  • 石家庄造价工程信息网长沙seo优化推荐
  • 深圳网站建_企业网站设计定制完整html网页代码案例