LeetCode 17.电话号码的字母组合
本文最后更新于615 天前,其中的信息可能已经过时,如有错误请发送邮件到tomding1065@gmail.com

题目链接/文章讲解:https://programmercarl.com/0017.%E7%94%B5%E8%AF%9D%E5%8F%B7%E7%A0%81%E7%9A%84%E5%AD%97%E6%AF%8D%E7%BB%84%E5%90%88.html

视频讲解:https://www.bilibili.com/video/BV1yV4y1V7Ug

这个题的思路挺简单的,就是在里面字符串转化为数字的部分int digit = digits[index] - '0';以及构造一个电话本的部分,已经将转化好的数字对应的字符储存在新的string里面需要我在做题中慢慢体会。

CPP

class Solution {
public:
    const string letterMap [10] = {
        "",
        "",
        "abc",
        "def",
        "ghi",
        "jkl",
        "mno",
        "pqrs",
        "tuv",
        "wxyz",

    };
    string s;
    vector<string>res;
    void backtracing(const string& digits, int index){
        if(index == digits.size()){
            res.push_back(s);
            return ;
        }
        
        int digit = digits[index] - '0';
        string letters = letterMap[digit];
        for(int i = 0; i<letters.size(); i++){
            s.push_back(letters[i]);
            backtracing(digits, index + 1);
            s.pop_back();
        }
    }
    vector<string> letterCombinations(string digits) {
        if(digits.size() == 0){
            return res;
        }
        backtracing(digits, 0);
        return res;
    }
};
文末附加内容
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇
Cream_dpl