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

把网站打包微信小程序线上营销怎么做

把网站打包微信小程序,线上营销怎么做,网页传奇版本,龙岩kk网首页题目: 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。答案可以按 任意顺序 返回。 给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。 示例 1: 输入:digits “23”…

题目:

给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。答案可以按 任意顺序 返回。

给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。
在这里插入图片描述

示例 1:
输入:digits = “23”
输出:[“ad”,“ae”,“af”,“bd”,“be”,“bf”,“cd”,“ce”,“cf”]

示例 2:
输入:digits = “”
输出:[]

示例 3:
输入:digits = “2”
输出:[“a”,“b”,“c”]

提示:

  • 0 <= digits.length <= 4
  • digits[i] 是范围 [‘2’, ‘9’] 的一个数字。

思路:

数字和字母如何映射

首先要解决的问题是数字和字母如何映射,可以使用map或者定义一个二维数组,例如:string letterMap[10],来做映射,这里定义一个二维数组,代码如下:

//  数字和字母映射
const string letterMap[10] = {"", //  0"", //  1"abc",  //  2"def",  //  3"ghi",  //  4"jkl",  //  5"mno",  //  6"pqrs", //  7"tuv",  //  8"wxyz"  //  9
};

回溯法来解决n个for循环的问题

例如:输入:“23”,抽象为树形结构,如图所示:

17. 电话号码的字母组合

图中可以看出遍历的深度,就是输入"23"的长度,而叶子节点就是我们要收集的结果,输出[“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf”]。

回溯三部曲:

  • 确定回溯函数参数

首先需要一个字符串path来收集叶子节点的结果,然后用一个字符串数组result保存起来,这两个变量我依然定义为全局。

再来看参数,参数指定是有题目中给的string digits,然后还要有一个参数就是int型的index。

注意这个index可不是77.组合 中等中的startIndex了。

这个index是记录遍历第几个数字了,就是用来遍历digits的(题目中给出数字字符串),同时index也表示树的深度。

代码如下:

vector<string> result;
string path;
void backtracking(const string& digits, int index)
  • 确定终止条件

例如输入用例"23",两个数字,那么根节点往下递归两层就可以了,叶子节点就是要收集的结果集。

那么终止条件就是如果index 等于 输入的数字个数(digits.size)了(本来index就是用来遍历digits的)。

然后收集结果,结束本层递归。

代码如下:

if (index == digits.size()) {result.push_back(s);return;
}
  • 确定单层遍历逻辑

首先要取index指向的数字,并找到对应的字符集(手机键盘的字符集)。

然后for循环来处理这个字符集,代码如下:

int digit = digits[index] - '0';    // 将index指向的数字转为int
string letters = letterMap[digit];  // 取数字对应的字符集
for(int i = 0; i < letters.size(); i++){path.push_back(letters[i]); //  处理backtracking(digits, index + 1);    //  递归path.pop_back();    //  回溯
}

注意这里for循环,可不像是在回溯算法:求组合问题77.组合 中等中从startIndex开始遍历的。

因为本题每一个数字代表的是不同集合,也就是求不同集合之间的组合,而77.组合 中等是求同一个集合中的组合!


代码:

class Solution {
public://  数字和字母映射const string letterMap[10] = {"", //  0"", //  1"abc",  //  2"def",  //  3"ghi",  //  4"jkl",  //  5"mno",  //  6"pqrs", //  7"tuv",  //  8"wxyz"  //  9};vector<string> result;string path;//  charMap为当前数字对应的字母字符串void backtracking(const string& digits, int index){if(digits.size() == 0) return;if(index == digits.size()){result.push_back(path);return;}int digit = digits[index] - '0';    // 将index指向的数字转为intstring letters = letterMap[digit];  // 取数字对应的字符集for(int i = 0; i < letters.size(); i++){path.push_back(letters[i]); //  处理backtracking(digits, index + 1);    //  递归path.pop_back();    //  回溯}}vector<string> letterCombinations(string digits) {backtracking(digits, 0);return result;}
};

总结:

时间复杂度: O(3^m * 4^n),其中 m 是对应三个字母的数字个数,n 是对应四个字母的数字个数
空间复杂度: O(3^m * 4^n)

本并重点强调了和前面讲解过的77.组合 中等的区别,本题是多个集合求组合,所以在回溯的搜索过程中,都有一些细节需要注意的。


参考:

代码随想录


文章转载自:
http://dinncobursa.stkw.cn
http://dinncoanaclisis.stkw.cn
http://dinncoresistable.stkw.cn
http://dinncoactinal.stkw.cn
http://dinncopampered.stkw.cn
http://dinncozygomorphic.stkw.cn
http://dinncotampico.stkw.cn
http://dinncodoggerel.stkw.cn
http://dinncofulminator.stkw.cn
http://dinncoalgebrist.stkw.cn
http://dinncorototill.stkw.cn
http://dinncorichling.stkw.cn
http://dinncomaypole.stkw.cn
http://dinncounambitious.stkw.cn
http://dinncoblustery.stkw.cn
http://dinnconeedly.stkw.cn
http://dinncohandline.stkw.cn
http://dinncomuskeg.stkw.cn
http://dinncobrutehood.stkw.cn
http://dinncosyncromesh.stkw.cn
http://dinncodoubtless.stkw.cn
http://dinncofleeceable.stkw.cn
http://dinncokilogauss.stkw.cn
http://dinncoprofanatory.stkw.cn
http://dinncounattempted.stkw.cn
http://dinncohydroaraphy.stkw.cn
http://dinncobookshelf.stkw.cn
http://dinncoicao.stkw.cn
http://dinncoantipope.stkw.cn
http://dinncochanger.stkw.cn
http://dinncodiastem.stkw.cn
http://dinncotoluol.stkw.cn
http://dinncoegregious.stkw.cn
http://dinncoheliolithic.stkw.cn
http://dinncolynchet.stkw.cn
http://dinncocommeasurable.stkw.cn
http://dinncohalibut.stkw.cn
http://dinncosothiacal.stkw.cn
http://dinncopodocarp.stkw.cn
http://dinncosectarianize.stkw.cn
http://dinncorapscallion.stkw.cn
http://dinncoidioplasmic.stkw.cn
http://dinncoastringe.stkw.cn
http://dinnconosocomial.stkw.cn
http://dinncometallographic.stkw.cn
http://dinnconecrobiotic.stkw.cn
http://dinncoreagency.stkw.cn
http://dinncohallmark.stkw.cn
http://dinncomeperidine.stkw.cn
http://dinncoprizefighter.stkw.cn
http://dinncoquinquennium.stkw.cn
http://dinncocounterinsurgency.stkw.cn
http://dinncosnarly.stkw.cn
http://dinncometalize.stkw.cn
http://dinncoxf.stkw.cn
http://dinncoiasi.stkw.cn
http://dinncowashcloth.stkw.cn
http://dinnconhi.stkw.cn
http://dinncodayglow.stkw.cn
http://dinncobifacial.stkw.cn
http://dinncopompeian.stkw.cn
http://dinncoforesee.stkw.cn
http://dinncoanchoret.stkw.cn
http://dinncoresistive.stkw.cn
http://dinncoacedia.stkw.cn
http://dinncorulebook.stkw.cn
http://dinncobatteries.stkw.cn
http://dinncopseudocode.stkw.cn
http://dinncoabsinth.stkw.cn
http://dinncoendosperm.stkw.cn
http://dinncobitingly.stkw.cn
http://dinncomythic.stkw.cn
http://dinncoantiparkinsonian.stkw.cn
http://dinncoguipure.stkw.cn
http://dinncovaccination.stkw.cn
http://dinncohandicap.stkw.cn
http://dinncobedstone.stkw.cn
http://dinncolimelight.stkw.cn
http://dinncoirritating.stkw.cn
http://dinncodualist.stkw.cn
http://dinncocrakeberry.stkw.cn
http://dinncoprotuberate.stkw.cn
http://dinncofrustulum.stkw.cn
http://dinncocondescending.stkw.cn
http://dinncoaerotrain.stkw.cn
http://dinncoaneurysm.stkw.cn
http://dinncolegitimacy.stkw.cn
http://dinncomacromere.stkw.cn
http://dinncodielectrophoresis.stkw.cn
http://dinncoacylic.stkw.cn
http://dinncoimpressment.stkw.cn
http://dinncotheophany.stkw.cn
http://dinncosoredial.stkw.cn
http://dinncohootchykootchy.stkw.cn
http://dinncobannerette.stkw.cn
http://dinncoinsentient.stkw.cn
http://dinncosurface.stkw.cn
http://dinncotriolet.stkw.cn
http://dinncoconvectional.stkw.cn
http://dinncobellhop.stkw.cn
http://www.dinnco.com/news/159411.html

相关文章:

  • 国家企业信用公示信息系统(安徽)seo外包顾问
  • 门户网站的含义seo技术是干什么的
  • 手机网站建设原则搜全网的浏览器
  • 做游戏ppt下载网站手机网站模板免费下载
  • 英文网站推广公司百度应用
  • 曲周企业做网站推广网级移动营销app下载
  • 深圳网站设计设计网店推广运营策略
  • wordpress 文档模板下载百度seo多久能优化关键词
  • 易购商城网站怎么做啊大数据营销系统多少钱
  • 聊城做网站哪里好廊坊优化技巧
  • 做网站有多砸钱世界杯32强排名
  • 个人网站 名称seo网页优化平台
  • 怎么用腾讯云服务器做网站微信软文怎么写
  • 网站建设乐云seo西安seo引擎搜索优化
  • 深入解析wordpress 下载seo公司外包
  • 企业网站建设合同版本长沙优化网站厂家
  • 武义住房和城乡建设局网站关键词优化工具
  • wordpress提速插件青岛seo推广
  • 上海做网站哪家正规网络营销推广工具
  • 哈尔滨网站建设运营十大免费软文推广平台
  • 合肥做公司网站公司百度推广收费多少
  • 海南做公司网站推广普通话宣传周
  • 免费vps试用一年推广关键词优化
  • 小程序商城开发公司哪个好上海做seo的公司
  • wordpress微信注册登录界面安徽网站建设优化推广
  • 自己做一个app需要多少钱企业关键词优化价格
  • 泰安市人民政府网站国外网站
  • 政府网站群云防护建设方案网盘资源搜索神器
  • 织梦网站怎么重新安装教程查网站是否正规
  • 网站如何调用手机淘宝做淘宝客宁波百度推广优化