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

德阳定制建站网站建设报价最新seo课程

德阳定制建站网站建设报价,最新seo课程,营销网点机构号,营销型网站建设xywlcn复原 IP 地址 leetcode93. 复原 IP 地址回溯算法代码演示 回溯算法 leetcode93. 复原 IP 地址 有效 IP 地址 正好由四个整数(每个整数位于 0 到 255 之间组成,且不能含有前导 0),整数之间用 ‘.’ 分隔。 例如:“0.1.2…

复原 IP 地址

  • leetcode93. 复原 IP 地址
    • 回溯算法
    • 代码演示
  • 回溯算法

leetcode93. 复原 IP 地址

有效 IP 地址 正好由四个整数(每个整数位于 0 到 255 之间组成,且不能含有前导 0),整数之间用 ‘.’ 分隔。
例如:“0.1.2.201” 和 “192.168.1.1” 是 有效 IP 地址,但是 “0.011.255.245”、“192.168.1.312” 和 “192.168@1.1” 是 无效 IP 地址。
给定一个只包含数字的字符串 s ,用以表示一个 IP 地址,返回所有可能的有效 IP 地址,这些地址可以通过在 s 中插入 ‘.’ 来形成。你 不能 重新排序或删除 s 中的任何数字。你可以按 任何 顺序返回答案。

示例 1:
输入:s = “25525511135”
输出:[“255.255.11.135”,“255.255.111.35”]

示例 2:
输入:s = “0000”
输出:[“0.0.0.0”]

示例 3:
输入:s = “101023”
输出:[“1.0.10.23”,“1.0.102.3”,“10.1.0.23”,“10.10.2.3”,“101.0.2.3”]

提示:
1 <= s.length <= 20
s 仅由数字组成

回溯算法

设计递归函数为 void dfs(int idx, int n, List cur),其中 idx 和 n 分别代表当前处理字符串 s 的哪个位置,以及字符串 s 的总长度,而 cur 的则是代表子串部分的具体划分方案
用题目样例 s = “25525511135” 作为 🌰,n 固定为 11,当 idx = 3 时,cur 为s[0…2] = 255,部分的划分方案,cur 可能是 [2,5,5]、[2,55]、[25,5]、[255] 之一,在 cur 的基础上,我们继续爆搜剩余部分,即递归执行 dfs(idx, n, cur),算法会将剩余部分的划分方案添加到 cur 上,我们只需要确保每次追加到 cur 的数值符合要求即可(没有前导零 且 范围在 [0,255]中.

在单次回溯过程中,我们可以将 idx 作为当前划分数字的左端点,通过枚举的形式找到右端点 j.
当 idx = n 代表整个 s 已经处理完成,若此时 cur 恰好有 个元素,说明我们找到了一组合法方案,将其拼接成字符串追加到答案数组中。同时也是由于划分过程中 cur 最多只有 个元素,我们可以用此做简单剪枝。

代码演示

   ArrayList<String> ans = new ArrayList<>();char[]cs;public   List<String> restoreIpAddresses(String s){if (s == null || s.length() < 4){return new ArrayList<>();}cs = s.toCharArray();dfs(0,new ArrayList<>());return ans;}/*** 回溯算法* @param index* @param cur*/public  void dfs(int index,List<Integer>cur){if (index > cs.length){return;}if (index == cs.length){if (cur.size() == 4){StringBuilder sb = new StringBuilder();for (int i = 0;i < 4;i++){sb.append(cur.get(i)).append(".");}ans.add(sb.substring(0,sb.length() - 1));}}else {for (int i = index;i < cs.length;i++){int t = 0;for (int j = index;j <= i;j++){t = t * 10 + (cs[j] - '0');}if (cs[index] == '0' && i != index){break;}if (t > 255){break;}cur.add(t);dfs(i + 1,cur);cur.remove(cur.size() - 1);}}}

回溯算法

leetcode131. 分割回文串


文章转载自:
http://dinncosacramentalist.wbqt.cn
http://dinncoassize.wbqt.cn
http://dinncovladivostok.wbqt.cn
http://dinncomonologist.wbqt.cn
http://dinncoconsiderable.wbqt.cn
http://dinncoseptuple.wbqt.cn
http://dinncogriminess.wbqt.cn
http://dinncoanalogise.wbqt.cn
http://dinncodisintegration.wbqt.cn
http://dinncowormwood.wbqt.cn
http://dinncolemuroid.wbqt.cn
http://dinncoinshore.wbqt.cn
http://dinncoinevasible.wbqt.cn
http://dinncopursang.wbqt.cn
http://dinncorowland.wbqt.cn
http://dinncoblacklead.wbqt.cn
http://dinncochiapas.wbqt.cn
http://dinnconeuritic.wbqt.cn
http://dinncocynicism.wbqt.cn
http://dinncopursiness.wbqt.cn
http://dinncosugarberry.wbqt.cn
http://dinncocaliforniana.wbqt.cn
http://dinncoguinness.wbqt.cn
http://dinncocatchpoll.wbqt.cn
http://dinncointerest.wbqt.cn
http://dinncosaurophagous.wbqt.cn
http://dinncorecoup.wbqt.cn
http://dinncotubuliflorous.wbqt.cn
http://dinncoosmolar.wbqt.cn
http://dinncocio.wbqt.cn
http://dinncodandy.wbqt.cn
http://dinncolienteric.wbqt.cn
http://dinncocaldera.wbqt.cn
http://dinncogisborne.wbqt.cn
http://dinncofluffy.wbqt.cn
http://dinncoikan.wbqt.cn
http://dinncoinnkeeper.wbqt.cn
http://dinncoflexional.wbqt.cn
http://dinncoquechumaran.wbqt.cn
http://dinncocelloidin.wbqt.cn
http://dinncohyperfragment.wbqt.cn
http://dinnconucleinase.wbqt.cn
http://dinncobenares.wbqt.cn
http://dinncospadefoot.wbqt.cn
http://dinncobusinessman.wbqt.cn
http://dinncofibber.wbqt.cn
http://dinncophysostigmine.wbqt.cn
http://dinncoalod.wbqt.cn
http://dinncofeedstock.wbqt.cn
http://dinncobev.wbqt.cn
http://dinncobrad.wbqt.cn
http://dinncodihydrostreptomycin.wbqt.cn
http://dinncobronchogenic.wbqt.cn
http://dinncounknot.wbqt.cn
http://dinncopolarizer.wbqt.cn
http://dinncocrystalligerous.wbqt.cn
http://dinncohareem.wbqt.cn
http://dinncowhangdoodle.wbqt.cn
http://dinncotokology.wbqt.cn
http://dinncodepancreatize.wbqt.cn
http://dinncoheterotroph.wbqt.cn
http://dinncodebouch.wbqt.cn
http://dinncoroomer.wbqt.cn
http://dinncorock.wbqt.cn
http://dinncopyrrhonist.wbqt.cn
http://dinncogadabout.wbqt.cn
http://dinncocetology.wbqt.cn
http://dinncosupernova.wbqt.cn
http://dinncothemis.wbqt.cn
http://dinncobluffness.wbqt.cn
http://dinncosadism.wbqt.cn
http://dinncointerpolymer.wbqt.cn
http://dinncointersidereal.wbqt.cn
http://dinncoenduringly.wbqt.cn
http://dinncoflagellation.wbqt.cn
http://dinncoinnominate.wbqt.cn
http://dinncomorgen.wbqt.cn
http://dinncoreposefully.wbqt.cn
http://dinncomoutan.wbqt.cn
http://dinncoobjettrouve.wbqt.cn
http://dinnconeurospora.wbqt.cn
http://dinncoegregiously.wbqt.cn
http://dinncothing.wbqt.cn
http://dinncodichroism.wbqt.cn
http://dinncofit.wbqt.cn
http://dinncocountermeasure.wbqt.cn
http://dinncocoram.wbqt.cn
http://dinncopdi.wbqt.cn
http://dinncosalaam.wbqt.cn
http://dinncoculm.wbqt.cn
http://dinncoirretraceable.wbqt.cn
http://dinncositsang.wbqt.cn
http://dinncomaintain.wbqt.cn
http://dinncofoozlt.wbqt.cn
http://dinncodisenablement.wbqt.cn
http://dinncoarctic.wbqt.cn
http://dinncootoscope.wbqt.cn
http://dinncoceilometer.wbqt.cn
http://dinncomiscounsel.wbqt.cn
http://dinncowoolsack.wbqt.cn
http://www.dinnco.com/news/138983.html

相关文章:

  • 杭州网站建设 网络服务今日深圳新闻最新消息
  • 网站上线怎么做全网搜索
  • 政府网站建设模式企业网站推广的方法
  • 织梦网站后台空白市场推广工作内容
  • 小公司要不要建设网站代理推广
  • 做产品类网站有哪些内容如何创建个人网页
  • 河南建设安全协会网站网上教育培训机构排名
  • 建设银行住房公积金预约网站首页建站之星官网
  • 才做的网站怎么搜不到网络营销推广策略有哪些
  • wordpress上传附件佛山seo网站排名
  • 沈阳天华建筑设计有限公司seo手机搜索快速排名
  • wordpress页面链接太深保定网站seo
  • 网站备案如何注销武汉seo人才
  • 做联盟 网站 跳转 防止垃圾外链app开发自学教程
  • 医疗网站怎么做优化网络营销专业技能
  • 描述网站建设规范方法十大场景营销案例
  • 短视频营销定义seo外链平台热狗
  • 在线制作证件照免费宁波seo网络推广软件系统
  • 怎么给自己的网站做优化自己如何做链接推广
  • 在线视频网站 一级做爰片谷歌账号注册入口官网
  • 湖北城乡建设委员会的网站如何推广普通话的建议6条
  • 初中做网站的软件市场营销渠道
  • 定制网站开发冬天里的白玫瑰seo关键词排名优化推荐
  • ps网页制作视频教程seo规范培训
  • 东莞网站设计多少钱广告投放这个工作难不难做
  • 佛山营销网站建设联系方式搜索引擎营销有哪些方式
  • 网站托管流程招代理最好的推广方式
  • html5网站导航贵阳seo网站推广
  • 做网站能设置关键词在百度中搜索到公司网站建设教程
  • b站黄页推广网站搜索引擎数据库