zoukankan      html  css  js  c++  java
  • leetcode131:letter-combinations-of-a-phone-number

    题目描述

    给出一个仅包含数字的字符串,给出所有可能的字母组合。
    数字到字母的映射方式如下:(就像电话上数字和字母的映射一样)
    Input:Digit string "23"Output:["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
    注意:虽然上述答案是按字典序排列的,但你的答案可以按任意的顺序给出

    Given a digit string, return all possible letter combinations that the number could represent.

    A mapping of digit to letters (just like on the telephone buttons) is given below.

    Input:Digit string "23"Output:["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].↵

    Note: 

    Although the above answer is in lexicographical order, your answer could be in any order you want.

    示例1

    输入

    复制
    "23"

    输出

    复制
    ["ad","ae","af","bd","be","bf","cd","ce","cf"]
    


    class Solution {
    private:
        map<char,string> mp={{'2',"abc"},{'3',"def"},{'4',"ghi"},{'5',"jkl"},{'6',"mno"},{'7',"pqrs"},{'8',"tuv"},{'9',"wxyz"}};
        vector<string> res;
        string temp;
    public:
        void combine(string &digits,int start){//回溯法
            if(start==digits.size()){
                res.push_back(temp);return;
            }
            for(int i=0;i<mp[digits[start]].size();i++){
                temp+=mp[digits[start]][i];
                combine(digits,start+1);
                temp.pop_back();
            }
        }
        vector<string> letterCombinations(string digits) {
            combine(digits,0);
            return res;
        }
    };
  • 相关阅读:
    ul做导航栏
    论布局,bfc,margin塌陷和合并,经典bug
    mon-hom
    新浪下拉菜单模仿
    JQ筛选方法,筛选父子元素
    JQuery筛选选择器
    JQuery隐式迭代
    python 和 C# DES加密
    交互设计[1]--设计心理学
    javascript学习(9)——[设计模式]单例
  • 原文地址:https://www.cnblogs.com/hrnn/p/13413802.html
Copyright © 2011-2022 走看看