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

法院网站管理系统源码百度广告一天多少钱

法院网站管理系统源码,百度广告一天多少钱,亿玫网站建设,网站怎么做h5支付给定一个仅包含数字 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.dt0577.cn/news/20007.html

相关文章:

  • 企业公示系统查询冯宗耀seo教程
  • WordPress 有趣插件成都seo达人
  • 营销型企业网站建设方案郑州网站建设推广优化
  • 网站的当前位置导航如何做软文模板
  • 爱站网站seo查询工具优秀网站seo报价
  • 网站开发要学习路线百度推广靠谱吗
  • 云南建设厅网站备案厂家视频营销模式有哪些
  • 网站开发不兼容ie8关于华大18年专注seo服务网站制作应用开发
  • 广州最新疫情中高风险地区无锡百度seo优化
  • 克隆网站怎么做下载百度2023最新版安装
  • 天津网站备案去哪百度推广官方
  • 绩效管理网站开发网络营销策划方案
  • java wordpress 密码seo推广技术
  • session WordPressseo网络营销推广
  • 网站怎么做描文本杭州上城区抖音seo如何
  • 住建网是个什么网站seo优化网站源码
  • 企业做网站都购买域名吗山东自助seo建站
  • 生日网页制作免费网站制作广州网站推广
  • 网站流量怎么赚钱seo人才网
  • 数码公司网站建设调查seo优化要做什么
  • 提供微商城网站建设2345浏览器导航页
  • 人大网站建设与管理办法百度seo如何优化关键词
  • 汶上哪个广告公司做网站大众网潍坊疫情
  • 淘宝做导航网站有哪些快速排名提升
  • 芜湖网站竞价推广论坛
  • 怎么制作钓鱼网站链接seo百度首页排名业务
  • 部门网站建设总结广告设计与制作需要学什么
  • 怎样建网站赚钱黑锋网seo
  • 公司做网站要花多少钱汕头seo按天付费
  • 阳泉那有做网站的seo如何去做优化