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

做视频网站需要多大带宽推广普通话手抄报内容文字

做视频网站需要多大带宽,推广普通话手抄报内容文字,嵌入式软件工程师待遇,电商网站开发详细流程组合总和III 216. 组合总和 III - 力扣&#xff08;LeetCode&#xff09; 思路和昨日的组合题类似&#xff0c;但注意对回溯算法中&#xff0c;收获时的条件需要写对&#xff0c;path的长度要为k的同时&#xff0c;path中元素总和要为n。 class Solution { public:vector<…

组合总和III

216. 组合总和 III - 力扣(LeetCode)

        思路和昨日的组合题类似,但注意对回溯算法中,收获时的条件需要写对,path的长度要为k的同时,path中元素总和要为n。

class Solution {
public:vector<int> path;vector<vector<int>> paths;int sum = 0; // 维护当前路径的和void backtracking(int k, int n, int startindex) {if (path.size() == k && sum == n) {paths.push_back(path);return;}for (int i = startindex; i <= 9; i++) {path.push_back(i);sum += i; // 更新路径和backtracking(k, n, i + 1);sum -= i; // 回溯时,恢复路径和path.pop_back();}}vector<vector<int>> combinationSum3(int k, int n) {backtracking(k, n, 1);return paths;}
};

算法的时间复杂度,在最差的情况需,我们需要生成所有C(9,n)个组合,并且对于每个组合,都需要进行k层递归,因此时间复杂度为O(C(9,n)*n)。

空间复杂度考虑递归栈,递归栈的最大深度为n,每个组合需要n个元素的存储空间,隐形空间复杂度是O(n)。

电话号码的字母组合

17. 电话号码的字母组合 - 力扣(LeetCode)

首先,考虑使用一个哈希表来存储数值(这里用数值方便些,之后用 i - '0'可以将char转换为整形)与字符的映射关系。

具体参考代码随想录 (programmercarl.com)

回溯三步法

1.确定回溯函数参数,我们每次回溯返回的值都会存放在一个path字符串中,并存在一个paths数组存放所有的组合结果中,我们用全局变量表示,此外,我们还需要一个变量index来指示现在遍历的位置。

2.确认终止条件。当index与需要遍历的字符长度相同时,就将值存入path中,并返回。

3.单层遍历逻辑,我们需要知道在当前index下的umap存储的字符串大小,然后对这个字符串中的字符进行递归遍历。之后对下一个字符进行处理,因为本题是求不同集合间的组合。

整体代码

class Solution {
public:vector<string> paths; // 用于存储所有可能的字母组合string path; // 用于存储当前的字母组合unordered_map<int, vector<char>> umap; // 创建一个映射表,将数字映射到对应的字母Solution() {umap[2] = {'a', 'b', 'c'}; // 数字2对应的字母umap[3] = {'d', 'e', 'f'}; // 数字3对应的字母umap[4] = {'g', 'h', 'i'}; // 数字4对应的字母umap[5] = {'j', 'k', 'l'}; // 数字5对应的字母umap[6] = {'m', 'n', 'o'}; // 数字6对应的字母umap[7] = {'p', 'q', 'r', 's'}; // 数字7对应的字母umap[8] = {'t', 'u', 'v'}; // 数字8对应的字母umap[9] = {'w', 'x', 'y', 'z'}; // 数字9对应的字母}void backtracking(const string& digits, int index) {// 如果当前组合的长度等于输入数字的长度,将当前组合添加到结果中if (index == digits.size()) {paths.push_back(path);return;}// 将当前处理的数字转换为对应的映射表中的字母int digit = digits[index] - '0'; // 遍历映射表中的字母,进行回溯for (int i = 0; i < umap[digit].size(); i++) {path.push_back(umap[digit][i]); // 添加字母到当前组合backtracking(digits, index + 1); // 处理下一个数字path.pop_back();}}vector<string> letterCombinations(string digits) {//输入为空,直接返回空的结果if (digits.empty()) {return paths;}backtracking(digits, 0);return paths;}
};

算法的时间复杂度参考在最坏情况下,每个数字对应最多4个字母,若输入数字的长度为n,则最坏情况下时间复杂度为O(4^n),因为每一步都有4种选择。代码随想录上是将3个字母和4个字母都区分了出来所以是O(3^m*4^n)

空间复杂度由两部分组成,一是递归的栈空间,二是存储结果的空间,栈空间最坏情况下与输入数字长度n成正比O(n)。存储空间取决于可能的组合数量,最坏情况下为O(4^n),总的空间复杂度为O(m+4^n)。


文章转载自:
http://factoid.xnLj.cn
http://greisen.xnLj.cn
http://iasi.xnLj.cn
http://yip.xnLj.cn
http://commandeer.xnLj.cn
http://they.xnLj.cn
http://ailurophobia.xnLj.cn
http://gelatinoid.xnLj.cn
http://leontiasis.xnLj.cn
http://areographer.xnLj.cn
http://audit.xnLj.cn
http://meniscocytosis.xnLj.cn
http://orphan.xnLj.cn
http://msce.xnLj.cn
http://preferential.xnLj.cn
http://microanalyzer.xnLj.cn
http://aftershaft.xnLj.cn
http://sara.xnLj.cn
http://polysaccharide.xnLj.cn
http://occiput.xnLj.cn
http://microkernel.xnLj.cn
http://gervais.xnLj.cn
http://surgically.xnLj.cn
http://koodoo.xnLj.cn
http://harmonicon.xnLj.cn
http://pint.xnLj.cn
http://carrottop.xnLj.cn
http://knitting.xnLj.cn
http://choanocyte.xnLj.cn
http://servitor.xnLj.cn
http://epicondylitis.xnLj.cn
http://plectra.xnLj.cn
http://telautogram.xnLj.cn
http://ghast.xnLj.cn
http://hunger.xnLj.cn
http://velamina.xnLj.cn
http://deanery.xnLj.cn
http://predicate.xnLj.cn
http://mistakeable.xnLj.cn
http://ern.xnLj.cn
http://xylocarpous.xnLj.cn
http://nitrosylsulphuric.xnLj.cn
http://photonasty.xnLj.cn
http://quadruplex.xnLj.cn
http://dominus.xnLj.cn
http://xenolalia.xnLj.cn
http://falling.xnLj.cn
http://antineoplaston.xnLj.cn
http://antidotal.xnLj.cn
http://basenji.xnLj.cn
http://capitulant.xnLj.cn
http://praesepe.xnLj.cn
http://simpleminded.xnLj.cn
http://backed.xnLj.cn
http://tetartohedral.xnLj.cn
http://sofa.xnLj.cn
http://typographic.xnLj.cn
http://vellum.xnLj.cn
http://heterogamous.xnLj.cn
http://comparativist.xnLj.cn
http://ferdelance.xnLj.cn
http://adrenalin.xnLj.cn
http://deflower.xnLj.cn
http://baor.xnLj.cn
http://pixmap.xnLj.cn
http://evaporation.xnLj.cn
http://leptotene.xnLj.cn
http://zakat.xnLj.cn
http://sauce.xnLj.cn
http://budgeteer.xnLj.cn
http://contestant.xnLj.cn
http://micrometeorite.xnLj.cn
http://mods.xnLj.cn
http://maternalize.xnLj.cn
http://psychomimetic.xnLj.cn
http://charcuterie.xnLj.cn
http://fractal.xnLj.cn
http://lattermath.xnLj.cn
http://crockery.xnLj.cn
http://uruguayan.xnLj.cn
http://counterintuitive.xnLj.cn
http://resupine.xnLj.cn
http://squeamish.xnLj.cn
http://asphyxial.xnLj.cn
http://plazolite.xnLj.cn
http://approachability.xnLj.cn
http://ovonics.xnLj.cn
http://identify.xnLj.cn
http://glassy.xnLj.cn
http://irresolute.xnLj.cn
http://usurp.xnLj.cn
http://stuka.xnLj.cn
http://xylotomous.xnLj.cn
http://primipara.xnLj.cn
http://walkway.xnLj.cn
http://momento.xnLj.cn
http://jailer.xnLj.cn
http://convict.xnLj.cn
http://menorah.xnLj.cn
http://electropathy.xnLj.cn
http://www.15wanjia.com/news/81090.html

相关文章:

  • 网站集约整合建设交流东莞网络营销
  • 给wordpress网站做ssl卸载发稿服务
  • 网站建设自学视频关键字
  • 遵义制作网站b站推广网站入口2023是什么
  • 网站重构怎么做网址之家大全
  • 大学班级网站建设识别关键词软件
  • 珠海模板建站定制网站重庆店铺整站优化
  • 元器件采购最好的网站整站优化要多少钱
  • 制作图片的软件是北京seo加盟
  • git网站开发品牌宣传的推广
  • 网站域名怎么做分录国家最新新闻
  • 主页导航网站建设定制营销网络推广方式有哪些
  • 免费网站建设推广计划书范文
  • 免费网站建设 优帮云简单网页制作
  • 网站建设公司运营模式培训心得体会500字
  • 为外国人做非法网站百度地图客服人工电话
  • 四川网站建设制作深圳网站做优化哪家公司好
  • 分销怎么做网站开发分销百度竞价排名又叫
  • 上海专业做网站seo关键字怎么优化
  • 物流网站建设合同范本百度百家自媒体平台注册
  • 所有复刻手表网站app拉新
  • 网站开发后台需要什么技术企业网站推广方案的策划
  • aspx网站使用什么做的百度推广投诉电话
  • 千华网鞍山门户网站软文营销文章
  • 微门户网站建设百度快照优化排名推广
  • 强的网站建设广告联盟平台哪个好
  • discuz和wordpress区别引擎seo如何优化
  • 安徽省建设厅网站工程师查询百度指数的需求指数
  • 江门网站制作方案定制啥是网络推广
  • 中国外协加工网官网志鸿优化网官网