17. Letter Combinations of a Phone Number

题目描述:

https://leetcode.com/problems/letter-combinations-of-a-phone-number/

mycode(c++):

class Solution {
public:
    vector letterCombinations(string digits) {
        if(digits==""){
            vector rt1;
            return rt1;
        }
        map mp ;
        mp['2'] = "abc";
        mp['3'] = "def";
        mp['4'] = "ghi";
        mp['5'] = "jkl";
        mp['6'] = "mno";
        mp['7'] = "pqrs";
        mp['8'] = "tuv";
        mp['9'] = "wxyz";
        int len = 1;
        for( int i = 0;i< digits.length();i++) {
            len = len * mp[digits.at(i)].length();
        }
        vector rt(len,"");

        int index = 0;
        int tp_len = len;
        for( int i = 0;i< digits.length();i++){
            index = 0;
            for( int j = 0;j

心得:

对于异常的处理,比如字符串是空串。
看似简单的组合问题,实际中却并不是特别容易用代码展示出来。必须实现才行。

你可能感兴趣的:(17. Letter Combinations of a Phone Number)