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;
        }
    };
  • 相关阅读:
    GitHub入门教程
    转:使用ActiveX插件时object显示问题,div被object标签遮挡的解决方案
    windows集成资料
    转:获取windows凭证管理器明文密码
    转: OVER() 系列函数介绍
    SQL Prompt 快捷键
    转:敏捷开发之Scrum扫盲篇
    转:修改IIS虚拟目录名称bat脚本
    转:EditPuls 5.0 注册码
    转:RowVersion 用法
  • 原文地址:https://www.cnblogs.com/hrnn/p/13413802.html
Copyright © 2011-2022 走看看