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

企业网站建设需要提供什么内容海口网站制作推广

企业网站建设需要提供什么内容,海口网站制作推广,国际新闻最新消息,国字型网站建设布局给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。答案可以按 任意顺序 返回。 给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。 示例 1: 输入:digits "23" 输出&…

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

给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母
que
示例 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'] 的一个数字。


AC:

/** @lc app=leetcode.cn id=17 lang=cpp** [17] 电话号码的字母组合*/// @lc code=start
class Solution {
private:const string letterMap[10] = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz",};
public:string s;vector<string> result;void backtracking(const string& digits, int index) {if(digits.size() == index) {result.push_back(s);return ;}int digit = digits[index] - '0';string letter = letterMap[digit];for(int i = 0; i < letter.size(); i++){s.push_back(letter[i]);backtracking(digits, index + 1);s.pop_back();}}vector<string> letterCombinations(string digits) {s.clear();result.clear();if(digits.size() == 0)return result;backtracking(digits, 0);return result;}
};
// @lc code=end

AC
The function uses a private member variable letterMap to map each digit to its corresponding set of letters. The letterMap is an array of strings, where each string represents the set of letters corresponding to a digit. For example, letterMap[2] is the string “abc”, which represents the letters ‘a’, ‘b’, and ‘c’ corresponding to the digit 2.

The function uses a recursive backtracking approach to generate all possible letter combinations. The backtracking function takes two arguments: the input string of digits and an index representing the current position in the input string. The function first checks if the current position is equal to the length of the input string. If so, it adds the current combination of letters to the result vector and returns.

If the current position is less than the length of the input string, the function retrieves the set of letters corresponding to the current digit using the letterMap array. It then iterates over each letter in the set and adds it to the current combination of letters. The function then recursively calls itself with the updated combination of letters and the next index. After the recursive call returns, the function removes the last letter from the combination of letters to backtrack and try the next letter in the set.

The letterCombinations function initializes the result vector and calls the backtracking function with the input string and an initial index of 0. If the input string is empty, the function returns an empty vector.

Overall, this implementation is a simple and efficient way to generate all possible letter combinations of a given string of digits using a backtracking algorithm. One possible way to improve the code would be to add error checking to ensure that the input string only contains digits. Additionally, the variable names could be more descriptive to make the code easier to read and understand.


How does the backtracking algorithm work in generating all possible letter combinations?

The backtracking algorithm used in this code works by recursively generating all possible letter combinations of a given string of digits. The algorithm uses a private member variable letterMap to map each digit to its corresponding set of letters.

The backtracking function takes two arguments: the input string of digits and an index representing the current position in the input string. The function first checks if the current position is equal to the length of the input string. If so, it adds the current combination of letters to the result vector and returns.

If the current position is less than the length of the input string, the function retrieves the set of letters corresponding to the current digit using the letterMap array. It then iterates over each letter in the set and adds it to the current combination of letters. The function then recursively calls itself with the updated combination of letters and the next index. After the recursive call returns, the function removes the last letter from the combination of letters to backtrack and try the next letter in the set.

The letterCombinations function initializes the result vector and calls the backtracking function with the input string and an initial index of 0 . If the input string is empty, the function returns an empty vector.

Overall, the backtracking algorithm works by generating all possible letter combinations of a given string of digits by recursively iterating over each digit and its corresponding set of letters. The algorithm uses a simple and efficient approach to generate all possible combinations of letters, and is a common technique used in many other combinatorial problems .

http://www.yayakq.cn/news/411335/

相关文章:

  • 北京企业网站设计报价百度我的订单查询
  • 响应式一页网站做网站站怎么赚钱
  • dede手机网站模板哦如何创建一个平台型公司
  • 同城的网站建设站长做什么网站赚钱
  • 广东省监理建设协会网站前端网站做多语言
  • 私密浏览器看片大全免费直播北京seo公司排名
  • 柯桥做网站有哪些公司wordpress 显示代码
  • 阿里做网站怎么做wordpress 自动升级
  • 坪山网站建设行情网站页面设计模板
  • 公司网站发展规划书做催收的网站
  • 做网站要求什么条件wordpress打开很卡
  • 大余做网站公司建立网站步骤
  • 各大网站推荐网站 功能呢
  • 网站建设第一品牌传奇网页链接
  • 做家政网上推广网站潜山云建站网站建设
  • 网站流量分析指标深圳市 网站建设450
  • 能不能同行网站做站长统计找工程承包找哪个平台
  • 转播网站如何做建设网站翻译英文
  • 网站企业贵州三线建设博物馆网站
  • 珠海图远建设公司网站wordpress调用内容前多少字
  • 建设的招标网站东莞新感染一例阳性
  • 网站开发毕业设计书锦州北京网站建设
  • 网址大全123手机版下载网站优化合同
  • 上海 建设工程质量监督站网站wordpress quform
  • 企业网站导航代码免费生成短链接
  • 江苏住房建设厅主办网站龙岩招聘求职网站有哪些
  • 自建站工具网站友链交换平台
  • 个人网站开发协议维护网站一年多少钱
  • 网站的模板演示怎么做桂林论坛网站有哪些
  • 南沙规划建设局网站上饶专业做网站建设