[LeetCode] 17. Letter Combinations of a Phone Number
来源:互联网 发布:动态寻路算法 编辑:程序博客网 时间:2024/05/29 06:28
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.
class Solution {public: vector<string> letterCombinations(string digits) { vector<string> res; string str; if (digits.size() > 0) letterCombinations(res, str, digits, 0); return res; }private: void letterCombinations(vector<string>& res, string& comb, string& digits, int nth) { if (nth == digits.size()) { res.push_back(comb); return; } int digit = digits[nth] - '0'; for (auto letter : digit2letter[digit]) { comb.push_back(letter); letterCombinations(res, comb, digits, nth + 1); comb.pop_back(); } } vector<vector<char>> digit2letter { {' '}, {}, {'a', 'b', 'c'}, {'d', 'e', 'f'}, {'g', 'h', 'i'}, {'j', 'k', 'l'}, {'m', 'n', 'o'}, {'p', 'q', 'r', 's'}, {'t', 'u', 'v'}, {'w', 'x', 'y', 'z'}, };};
阅读全文
0 0
- LeetCode: Letter Combinations of a Phone Number
- LeetCode Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- [Leetcode] Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- 【leetcode】Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- [LeetCode]Letter Combinations of a Phone Number
- LeetCode-Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- LeetCode - Letter Combinations of a Phone Number
- LeetCode:Letter Combinations of a Phone Number
- LeetCode | Letter Combinations of a Phone Number
- leetcode Letter Combinations of a Phone Number
- Leetcode: Letter Combinations of a Phone Number
- 【leetcode】Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- leetcode: Letter Combinations of a Phone Number
- laravel框架总结 -- 软删除
- Jrtplib发送视频文件 + FFMPEG解码+VFW播放视频 (回调方式)
- DeepLearnToolbox-master CNN源码拙见
- vue.js入门环境搭建
- 加分二叉树 区间dp
- [LeetCode] 17. Letter Combinations of a Phone Number
- 我的vim配置
- 无人机设计(基于UG的固定翼滑翔式飞机的机械部分)
- CF 809C about proof of previous solution
- SpringMVC学习(五) 视图和视图解析器
- spring学习之spring框架介绍
- Activity的创建,配置上下文,绘制视图过程
- Ordering Tasks
- 【Unity3D入门】Unity3D学习笔记004——Unity中的五个视图窗口