zoukankan      html  css  js  c++  java
  • Letter Combinations of a Phone Number

    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     string table[10] = {"","", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
     2     void search(vector<string> &result, string tmp, string digits, int cur){
     3         if(cur == digits.length()){
     4             result.push_back(tmp);
     5             return;
     6         }
     7         tmp += " ";
     8         for(int i = 0; i < table[digits[cur]-'0'].length(); i++){
     9             tmp[cur] = table[digits[cur]-'0'][i];
    10             search(result, tmp, digits, cur+1);
    11         }
    12     }
    13     vector<string> letterCombinations(string digits) {
    14         vector<string> result;
    15         string tmp = "";
    16         search(result, tmp, digits, 0);
    17         return result;
    18     }
  • 相关阅读:
    JVM参数配置
    域渗透命令
    相对路径绝对路径
    ESPCMS的CSRF添加管理员账号
    nmap脚本nse的使用
    Nmap简单的漏扫
    MS08-067
    lcx用法
    给自己的服务器传文件 转自别人
    突破大文件上传 和内网ip的端口转发
  • 原文地址:https://www.cnblogs.com/waruzhi/p/3416133.html
Copyright © 2011-2022 走看看