zoukankan      html  css  js  c++  java
  • Leetcode 17. Letter Combinations of a Phone Number(水)

    17. Letter Combinations of a Phone Number
    Medium

    Given a string containing digits from 2-9 inclusive, 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. Note that 1 does not map to any letters.

    Example:

    Input: "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 class Solution {
     2 public:
     3     vector<string> letterCombinations(string digits) {
     4         map<char,string> test;
     5         test['2'] = "abc";
     6         test['3'] = "def";
     7         test['4'] = "ghi";
     8         test['5'] = "jkl";
     9         test['6'] = "mno";
    10         test['7'] = "pqrs";
    11         test['8'] = "tuv";
    12         test['9'] = "wxyz";
    13         vector<string> fa_;
    14         vector<string> chil_;
    15         fa_.push_back("");
    16         for(int i = 0; i < digits.length(); i++){
    17             chil_.clear();
    18             for(int j = 0; j < fa_.size(); j++){
    19                 //printf("%d %s",test[digits[i]].length());
    20                 for(int k = 0; k < test[digits[i]].length(); k++){
    21                     //printf("%s",test[digits[i]][k]);
    22                     chil_.push_back(fa_[j]+test[digits[i]][k]);
    23                 }
    24             }
    25             fa_ = chil_;
    26         }
    27         return chil_;
    28     }
    29 };
  • 相关阅读:
    MFC绘图机制(二)-双缓存
    C89:论数组/指针/引用
    C89:论预处理命令
    图像优化大坑
    MFC 对话框和属性表
    jQuery-plugin-pagePiling
    jquery-ui-chosen
    JavaScript DOM编程艺术小笔记
    微信公众号素材
    iOS沙箱传值
  • 原文地址:https://www.cnblogs.com/shanyr/p/11518389.html
Copyright © 2011-2022 走看看