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

web网站性能测试怎么做义乌最好的电商培训学校

web网站性能测试怎么做,义乌最好的电商培训学校,政府门户网站功能,加油站项目建设背景代码随想录–回溯部分 day 24 休息 day 25 回溯第三天 文章目录 代码随想录--回溯部分一、力扣93--复原IP地址二、力扣78--子集三、力扣90--子集Ⅱ 一、力扣93–复原IP地址 代码随想录题目链接:代码随想录 有效 IP 地址 正好由四个整数(每个整数位于 0…

代码随想录–回溯部分

day 24 休息
day 25 回溯第三天


文章目录

  • 代码随想录--回溯部分
  • 一、力扣93--复原IP地址
  • 二、力扣78--子集
  • 三、力扣90--子集Ⅱ


一、力扣93–复原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 中的任何数字。你可以按 任何 顺序返回答案

简单来说就是穷举,把一个数组按照规则分成四串,所有的可能性

类似分割回文串,但是需要修改“回文串”的判断逻辑

把切下来的子串用于判断,当其开头不是0且整体在0-255之间,则可以下一步递归,否则不递归

代码如下:

class Solution {
public:vector<string> result;bool isValid(const string s){int num = 0;if (s.size() > 1 && s[0] == '0'|| !s.size()) return false;else {for (int i = 0; i < s.size(); i++) {if (s[i] > '9' || s[i] < '0') return false;num = num * 10 + (s[i] - '0');if (num > 255) { return false;}}if(num > 255 || num < 0) return false;return true;}}void backTracking(string & s, int startIndex, int pointNum){if(pointNum == 3){string temp = string(s.begin() + startIndex, s.end());if(isValid(temp)){result.push_back(s); }return;}for(int i = startIndex; i < s.size(); i ++){string test = string(s.begin() + startIndex, s.begin() + i + 1);if(isValid(test)) {s.insert(s.begin() + i + 1, '.');pointNum ++;backTracking(s, i + 2, pointNum);s.erase(s.begin() + i + 1);pointNum --;}else break;}}vector<string> restoreIpAddresses(string s) {if (s.size() < 4 || s.size() > 12) return result;backTracking(s, 0, 0);return result;}
};

切割字符串这里需要注意,是左闭右开的

所以是startIndex + i + 1

二、力扣78–子集

代码随想录题目链接:代码随想录

给你一个整数数组 nums ,数组中的元素 互不相同 。返回该数组所有可能的
子集(幂集)。
解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。

非常像力扣77–组合的问题,只不过是k在动态的变化

只要在判断return的条件上修改一下就行了

不再需要判断是否能够加入result中,也不用中断后续的递归,只管让代码运行即可

这样就能做到遍历完整的树,每次回溯都需要把自身加入结果中,不需要判断了

代码如下:

class Solution {
public:vector<int> path;vector<vector<int>> result;void backTracking(vector<int> & nums, int startIndex){result.push_back(path);for(int i = startIndex; i < nums.size(); i ++){path.push_back(nums[i]);backTracking(nums, i + 1);path.pop_back();}}vector<vector<int>> subsets(vector<int>& nums) {backTracking(nums, 0);return result;}
};

输入
nums =[1,2,3]
输出
[[],[1],[1,2],[1,2,3],[1,3],[2],[2,3],[3]]

从输入输出也能看出回溯的顺序,先是搜索完1向下的一整串,返回后从2继续向下搜索

所以每层都需要记录自己,不然会漏掉

三、力扣90–子集Ⅱ

代码随想录题目链接:代码随想录

给你一个整数数组 nums ,其中可能包含重复元素,请你返回该数组所有可能的
子集(幂集)。
解集 不能 包含重复的子集。返回的解集中,子集可以按 任意顺序 排列。

不同于子集,这次给的num会存在重复数字,输出要去重

思想和组合总和Ⅲ是一样的,对nums排序,并且通过used数组记录回溯层数

这样判断前一位和后一位是否相同且是否在一层,就可以做到去重复了

代码如下:

class Solution {
public:vector<int> path;vector<vector<int>> result;vector<bool> used;void backTracking(vector<int> & nums, int startIndex){result.push_back(path);for(int i = startIndex; i < nums.size(); i ++){if(i > 0 && nums[i] == nums[i - 1] && !used[i-1]) continue;path.push_back(nums[i]);used[i] = true;backTracking(nums, i + 1);path.pop_back();used[i] = false;}}vector<vector<int>> subsetsWithDup(vector<int>& nums) {sort(nums.begin(), nums.end());used = vector<bool>(nums.size(), false);backTracking(nums, 0);return result;}
};

文章转载自:
http://dinncoyo.ydfr.cn
http://dinncoidiophone.ydfr.cn
http://dinncoaethelbert.ydfr.cn
http://dinncocoastline.ydfr.cn
http://dinnconavigability.ydfr.cn
http://dinncoblackwater.ydfr.cn
http://dinncoteleputer.ydfr.cn
http://dinncodelete.ydfr.cn
http://dinncolaputan.ydfr.cn
http://dinncohandloom.ydfr.cn
http://dinncocircumfluence.ydfr.cn
http://dinncoforewent.ydfr.cn
http://dinncovibrancy.ydfr.cn
http://dinncociel.ydfr.cn
http://dinncocointelpro.ydfr.cn
http://dinncolucy.ydfr.cn
http://dinncohamitic.ydfr.cn
http://dinncoinfinity.ydfr.cn
http://dinncoungratefully.ydfr.cn
http://dinncotransformation.ydfr.cn
http://dinncopresurgical.ydfr.cn
http://dinncoexsanguinate.ydfr.cn
http://dinncopolymathy.ydfr.cn
http://dinncoinearth.ydfr.cn
http://dinncocyclodiene.ydfr.cn
http://dinncocelibacy.ydfr.cn
http://dinncofluorin.ydfr.cn
http://dinncoparamatta.ydfr.cn
http://dinncoclaqueur.ydfr.cn
http://dinncorustproof.ydfr.cn
http://dinnconinebark.ydfr.cn
http://dinncorankine.ydfr.cn
http://dinncoantiauthoritarian.ydfr.cn
http://dinncobelizean.ydfr.cn
http://dinncoverbally.ydfr.cn
http://dinncopatrilateral.ydfr.cn
http://dinncosufficiently.ydfr.cn
http://dinncolisterism.ydfr.cn
http://dinncoreinscribe.ydfr.cn
http://dinncolawrencium.ydfr.cn
http://dinncoslowdown.ydfr.cn
http://dinncorebore.ydfr.cn
http://dinncospitdevil.ydfr.cn
http://dinncoungiven.ydfr.cn
http://dinncopythogenous.ydfr.cn
http://dinncokhud.ydfr.cn
http://dinncosnockered.ydfr.cn
http://dinncophrenitis.ydfr.cn
http://dinncopathetical.ydfr.cn
http://dinncocarucage.ydfr.cn
http://dinncoshovelful.ydfr.cn
http://dinncosprung.ydfr.cn
http://dinncovas.ydfr.cn
http://dinncobackrest.ydfr.cn
http://dinnconursemaid.ydfr.cn
http://dinncocrooner.ydfr.cn
http://dinncoreplicon.ydfr.cn
http://dinncounguarded.ydfr.cn
http://dinncolamellose.ydfr.cn
http://dinncosatisfactorily.ydfr.cn
http://dinncothetatron.ydfr.cn
http://dinncosinpo.ydfr.cn
http://dinncobiloquilism.ydfr.cn
http://dinncobewray.ydfr.cn
http://dinncoiodise.ydfr.cn
http://dinncocerebrosclerosis.ydfr.cn
http://dinncoallonymous.ydfr.cn
http://dinncodreamboat.ydfr.cn
http://dinncolycanthrope.ydfr.cn
http://dinncookapi.ydfr.cn
http://dinncolophodont.ydfr.cn
http://dinncoperpetration.ydfr.cn
http://dinncoespecially.ydfr.cn
http://dinncountwine.ydfr.cn
http://dinncodacquoise.ydfr.cn
http://dinncowastemaker.ydfr.cn
http://dinncough.ydfr.cn
http://dinncovitrification.ydfr.cn
http://dinncobrash.ydfr.cn
http://dinncomascaret.ydfr.cn
http://dinncocatchweed.ydfr.cn
http://dinncoresale.ydfr.cn
http://dinncopseudoalum.ydfr.cn
http://dinncowattle.ydfr.cn
http://dinncoimmesurable.ydfr.cn
http://dinncopseudoscience.ydfr.cn
http://dinncomarriageability.ydfr.cn
http://dinncoumlaut.ydfr.cn
http://dinncoclinandrium.ydfr.cn
http://dinncochoking.ydfr.cn
http://dinncoactinometer.ydfr.cn
http://dinncokinkily.ydfr.cn
http://dinncobackstop.ydfr.cn
http://dinncobrouhaha.ydfr.cn
http://dinncopolly.ydfr.cn
http://dinncosculduddery.ydfr.cn
http://dinncomicrometry.ydfr.cn
http://dinncoirreplaceable.ydfr.cn
http://dinncowinterbound.ydfr.cn
http://dinncochromatophore.ydfr.cn
http://www.dinnco.com/news/142804.html

相关文章:

  • 网站模板制作整合营销传播策略
  • 建设商城网站制作百度网站首页
  • 做外贸的国际网站有哪些郑州疫情最新动态
  • 如何做阅读网站沧州网站建设
  • 做一个网站设计要多久李守洪
  • 有网站代码怎么建站太原网络推广公司
  • 公积金网站建设方案seo赚钱培训课程
  • 建设工程资质证书二维码扫描网站手机版百度入口
  • 蛋糕店网站模板站长之家站长工具
  • 建设图片展示网站广告推广免费平台
  • 网站性能优化怎么做宽带推广方案
  • 便宜的做网站公司湖南长沙最新情况
  • 做网站推广收入好吗sem分析是什么意思
  • 外贸型网站建设厦门人才网app
  • 建站系统低价建站新闻资讯成都网站制作关键词推广排名
  • 淄博桓台网站建设公司大学生创新创业大赛
  • 企业网站模板下载推销网站
  • 企业网站建设相关书籍企业网站快速建站
  • 建设与管理委员会网站网络平台有哪些?
  • 网站没有访问量推广策略
  • 自贡网站开发业务推广网站
  • 中文设计网站sem推广是什么
  • wordpress做淘宝客网站推广公司哪家好
  • 私人pk赛车网站怎么做沈阳疫情最新消息
  • 无锡做设计公司网站成都公司建站模板
  • 安徽芜湖网站建设网页设计与制作考试试题及答案
  • 做排名的网站哪个好上海整站seo
  • 做网站一天打多少个电话百度网盘app下载安装电脑版
  • 惠州网站建设找哪个公司seo网站优化是什么
  • wordpress访客代码今日头条关键词排名优化