Letter Combinations of a Phone Number
来源:互联网 发布:得力考勤机数据导出 编辑:程序博客网 时间:2024/05/01 19:36
一、问题描述
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"].
二、思路
将数字对应的字符存入chamap中,这样我们可以一次遍历每一个数字对应字符串的每一个字符。
三、代码
class Solution {public: vector<string> letterCombinations(string digits) { vector<string> v; int n = digits.size(); if(n == 0) return v; v.push_back(""); string charmap[10] = {"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; for(int i = 0; i < n; ++i){ vector<string> temp; string chars = charmap[digits[i] - '0']; for (int j = 0; j < chars.size(); j++) for (int k = 0; k < v.size(); k++) temp.push_back(v[k] + chars[j]); v = temp; } return v; }};
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
- LeetCode18:Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- 【leetcode】Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- [LeetCode]Letter Combinations of a Phone Number
- LeetCode-Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- LeetCode - Letter Combinations of a Phone Number
- LeetCode:Letter Combinations of a Phone Number
- pyqt4文档阅读(7.3):QSizeF-QPointF-QRectF
- 多实例MySQL安装
- git删除未跟踪文件
- jquery实现图片放大功能
- 条件判断用法
- Letter Combinations of a Phone Number
- 同源策略和跨域访问
- android 签名
- Sort Colors 三色排序
- 《吴中田妇叹》和《江城子.别徐州》
- JPA是什么?他和Hibernate什么关系?
- 获取文件夹下的文件和文件夹
- Angular $location 获取 url 参数
- RecyclerView实现瀑布流