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 };
  • 相关阅读:
    一次排查线上接口偶发异常耗时引起的思考!
    台阶很高,青蛙跳不跳?
    从零开始认识堆排序
    Redis SDS 深入一点,看到更多!
    偏见是怎么产生的?
    TCP 粘包拆包
    Netty中的这些知识点,你需要知道!
    心有 netty 一点通!
    服务化最佳实践
    职场的“诱惑”?
  • 原文地址:https://www.cnblogs.com/shanyr/p/11518389.html
Copyright © 2011-2022 走看看