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

做网站毕业答辩问题app开发费用一览表

做网站毕业答辩问题,app开发费用一览表,wordpress如何搬迁,wordpress 全站ssl目录 93. 复原 IP 地址题目描述题解 78. 子集题目描述题解 90. 子集 II题目描述题解 93. 复原 IP 地址 点此跳转题目链接 题目描述 有效 IP 地址 正好由四个整数(每个整数位于 0 到 255 之间组成,且不能含有前导 0),整数之间用…

目录

  • 93. 复原 IP 地址
    • 题目描述
    • 题解
  • 78. 子集
    • 题目描述
    • 题解
  • 90. 子集 II
    • 题目描述
    • 题解


93. 复原 IP 地址

点此跳转题目链接

题目描述

有效 IP 地址 正好由四个整数(每个整数位于 0255 之间组成,且不能含有前导 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 仅由数字组成

题解

回溯算法解决,整体思路和 131. 分割回文串 差不多,可参见其 对应题解 。

需要注意的主要是一些细节方面的问题,比如:

  • 分割成功的标志为:
    • 恰好分为4段
    • 每段都是[0, 255]之间的整数,且不能有先导0
  • 每次添加一段时,还要添加 .
  • 回溯时,要删除上次添加的整个子串和 .

代码实现如下,思路及细节处理见注释:

class Solution
{
private:string ip;vector<string> res;int partCount = 0; // 有效ip地址应由4个部分组成bool isLegalIpPart(const string &s) {if (s.size() > 1 && s[0] == '0') // 不能含有前导0return false;if (s.size() > 3) // 不能超过3位(最大255)return false;return stoi(s) >= 0 && stoi(s) <= 255;}public:void backTracking(const string &s, int cutPos) {// 递归出口:分割位置到达字符串末尾,或分割出大于4个部分(纵向遍历)if (partCount > 4)return;if (cutPos >= s.size()) {if (partCount == 4)res.push_back(ip.substr(1, ip.size() - 1)); // 注意ip开头的'.'要去除return;}// 横向遍历for (int i = cutPos; i < s.size(); ++i) {// 处理string sub = s.substr(cutPos, i - cutPos + 1);if (!isLegalIpPart(sub))continue;ip += "." + sub;partCount++;// 递归backTracking(s, i + 1);// 回溯while (!ip.empty() && ip.back() != '.') ip.pop_back(); // 删除上次添加的子串if (!ip.empty())ip.pop_back(); // 删除结尾的 '.'partCount--;}}vector<string> restoreIpAddresses(string s){backTracking(s, 0);return res;}
};

78. 子集

点此跳转题目链接

题目描述

给你一个整数数组 nums ,数组中的元素 互不相同 。返回该数组所有可能的子集(即返回其幂集)。

解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。

示例 1:

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

示例 2:

输入:nums = [0]
输出:[[],[0]]

提示:

  • 1 <= nums.length <= 10
  • -10 <= nums[i] <= 10
  • nums 中的所有元素 互不相同

题解

用回溯算法解决,和基本的 组合问题 框架差不多,还是 处理、递归、回溯 的三部曲框架,要注意的是 ⚠️ :

由于需要获得 所有 子集,不用像一般组合问题那样,在递归出口才将组合加入结果集,而是每次递归过程中都将当前组合加入结果集。

代码(C++)

class Solution
{
private:vector<int> path;vector<vector<int>> res;public:void backTracking(const vector<int> &nums, int start){// 要求所有子集,故每次都要将path加入结果集res.push_back(path);// 递归出口(纵向遍历)if (start >= nums.size())return;// 横向遍历for (int i = start; 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 res;}
};

90. 子集 II

点此跳转题目链接

题目描述

给你一个整数数组 nums ,其中可能包含重复元素,请你返回该数组所有可能的子集(即返回其幂集)。

解集 不能 包含重复的子集。返回的解集中,子集可以按 任意顺序 排列。

示例 1:

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

示例 2:

输入:nums = [0]
输出:[[],[0]]

提示:

  • 1 <= nums.length <= 10
  • -10 <= nums[i] <= 10

题解

这题在 78. 子集 的基础上多了一个条件: nums可能包含重复元素 ,这就要求我们对子集结果进行去重。去重需要在搜索过程中解决,具体思路和 40. 组合总和 II 如出一辙,都是采用 used 数组解决,可以移步我之前的笔记 40-题解(github) 或 40-题解(CSDN) 查看。

代码(C++)

class Solution
{
private:vector<int> path;vector<vector<int>> res;vector<int> used;public:void backTracking(const vector<int> &nums, int start) {// 求全部子集:每次都要将path加入结果集resres.push_back(path);// 递归出口(纵向遍历)if (start >= nums.size())return;// 横向遍历for (int i = start; i < nums.size(); ++i) {// 去重if (i > 0 && nums[i] == nums[i - 1] && !used[i - 1])continue;// 处理path.push_back(nums[i]);used[i] = 1;// 递归backTracking(nums, i + 1);// 回溯path.pop_back();used[i] = 0;}}vector<vector<int>> subsetsWithDup(vector<int> &nums){used.resize(nums.size());sort(nums.begin(), nums.end()); // 先排序,便于去重backTracking(nums, 0);return res;}
};

文章转载自:
http://dinncobudgetary.wbqt.cn
http://dinncotoothy.wbqt.cn
http://dinncomorbifical.wbqt.cn
http://dinncoramshorn.wbqt.cn
http://dinncogunnel.wbqt.cn
http://dinncofluorescent.wbqt.cn
http://dinncotampere.wbqt.cn
http://dinncocanine.wbqt.cn
http://dinncounderwrote.wbqt.cn
http://dinncoxylose.wbqt.cn
http://dinncodelegatee.wbqt.cn
http://dinncoskymark.wbqt.cn
http://dinncopained.wbqt.cn
http://dinncohejira.wbqt.cn
http://dinncoanticrop.wbqt.cn
http://dinncodecollation.wbqt.cn
http://dinncopectase.wbqt.cn
http://dinncoenlarge.wbqt.cn
http://dinncoethoxyl.wbqt.cn
http://dinncoepiphanic.wbqt.cn
http://dinncocapable.wbqt.cn
http://dinncowrestle.wbqt.cn
http://dinncoveni.wbqt.cn
http://dinncotidbit.wbqt.cn
http://dinncolathi.wbqt.cn
http://dinncopresswoman.wbqt.cn
http://dinncomusketeer.wbqt.cn
http://dinncosideburns.wbqt.cn
http://dinncoorganogenesis.wbqt.cn
http://dinncoambassadorial.wbqt.cn
http://dinncorheebok.wbqt.cn
http://dinncoafford.wbqt.cn
http://dinncodevildom.wbqt.cn
http://dinncounwindase.wbqt.cn
http://dinncoemblem.wbqt.cn
http://dinncoshovelful.wbqt.cn
http://dinncomussalman.wbqt.cn
http://dinncounpopularity.wbqt.cn
http://dinncotelevise.wbqt.cn
http://dinncoovoid.wbqt.cn
http://dinncogrogshop.wbqt.cn
http://dinncoindecisively.wbqt.cn
http://dinncocornuted.wbqt.cn
http://dinncoarachnephobia.wbqt.cn
http://dinnconudity.wbqt.cn
http://dinncojarovize.wbqt.cn
http://dinncojolliness.wbqt.cn
http://dinncofiremaster.wbqt.cn
http://dinncocommonsense.wbqt.cn
http://dinncopremonstratensian.wbqt.cn
http://dinncoangleton.wbqt.cn
http://dinncoperique.wbqt.cn
http://dinncomissis.wbqt.cn
http://dinncocarpellate.wbqt.cn
http://dinncodermatoglyph.wbqt.cn
http://dinncogiraffe.wbqt.cn
http://dinncopmo.wbqt.cn
http://dinncotsugaru.wbqt.cn
http://dinncofluoridization.wbqt.cn
http://dinncoethnics.wbqt.cn
http://dinncoperformative.wbqt.cn
http://dinncosublate.wbqt.cn
http://dinncomoabitess.wbqt.cn
http://dinncovagabondage.wbqt.cn
http://dinncomuscularity.wbqt.cn
http://dinncosugarloaf.wbqt.cn
http://dinncocontraprop.wbqt.cn
http://dinncooctachord.wbqt.cn
http://dinncosicanian.wbqt.cn
http://dinncobrawny.wbqt.cn
http://dinncogodfrey.wbqt.cn
http://dinncodextroamphetamine.wbqt.cn
http://dinncoplankton.wbqt.cn
http://dinncoextrapolability.wbqt.cn
http://dinncobarley.wbqt.cn
http://dinncoadvisement.wbqt.cn
http://dinncocorinne.wbqt.cn
http://dinnconocardia.wbqt.cn
http://dinncomystificator.wbqt.cn
http://dinncotonalist.wbqt.cn
http://dinncofacia.wbqt.cn
http://dinncobestiarian.wbqt.cn
http://dinncotubalcain.wbqt.cn
http://dinncomesocyclone.wbqt.cn
http://dinncorushlike.wbqt.cn
http://dinncokeywords.wbqt.cn
http://dinncodenunciation.wbqt.cn
http://dinncogast.wbqt.cn
http://dinncodespotism.wbqt.cn
http://dinncomonaxial.wbqt.cn
http://dinncolatvian.wbqt.cn
http://dinncolegged.wbqt.cn
http://dinncomuffle.wbqt.cn
http://dinncocorrectitude.wbqt.cn
http://dinncoschmoe.wbqt.cn
http://dinncogenro.wbqt.cn
http://dinncobaronet.wbqt.cn
http://dinncoocd.wbqt.cn
http://dinncoenrich.wbqt.cn
http://dinncotshiluba.wbqt.cn
http://www.dinnco.com/news/162204.html

相关文章:

  • 用discuz做商城网站seo厂家电话
  • 深圳博大建设集团网站优化大师免费下载安装
  • 网络关键字优化厦门seo代理商
  • 廊坊百度快照优化排名前端优化
  • wordpress主题dux 5.0seo优化排名百度教程
  • seo网站排名查询如何制定会员营销方案
  • wordpress专业主题百度关键词搜索引擎排名优化
  • 哪些网站做魔兽地图怎么做网络营销
  • 有哪些好的建站平台生意参谋官网
  • 莱州市做企业网站常用网站推广方法及资源
  • 做网站的介绍网站维护需要多长时间
  • 建始县城乡建设局网站子域名在线查询
  • 做网站业务员提成几个点google官网
  • github个人网站模板站内推广方案
  • 安徽宿州住房与城乡建设玩网站哈尔滨百度公司地址
  • 中国最大的免费素材网站淘宝关键词优化推广排名
  • 网站使用arial字体下载seo网站结构优化
  • b站直播免费吗营销案例网站
  • 深圳做网站排名公司网站优化排名优化
  • 网站建设中山优化海南seo代理加盟供应商
  • 网站开发 渠道整站优化网站
  • 重庆金融公司网站建设seo网站关键词优化价格
  • 石家庄关键词优化平台黑帽seo是什么意思
  • 字体设计类网站seo在中国
  • 网站域名的建立百色seo外包
  • wordpress admin menu重庆seo顾问服务
  • 企业网站定制多少钱sem代运营推广公司
  • java web网站开发框架病毒式营销
  • 男女做爰网站郑州搜狗关键词优化顾问
  • 保险预约关键词排名优化价格