Leetcode123: Letter Combinations of a Phone Number
来源:互联网 发布:SQL distinct 记录数 编辑:程序博客网 时间:2024/06/06 09:47
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) { string str[] = {"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; int n = digits.size(); vector<string> res; if(!n) return res; res.resize(1); for(int i = 0; i < n; i++) { for(int j = res.size()-1; j >= 0; j--) { string s = str[digits[i]-'2']; for(int k = s.size()-1; k>=0; k--) { if(k) res.push_back(res[j]+s[k]); else res[j] += s[k]; } } } return res; }};
1 0
- Leetcode123: 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
- 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
- java String字符串替换
- Android中软键盘InputMethodManager的弹出和隐藏,以及显示和隐藏的监听
- android library工程中使用switch_case语句,调用资源文件的id出现错误的原因分析及解决方法
- 如何打包Volley成jar文件
- 25个必须记住的SSH命令
- Leetcode123: Letter Combinations of a Phone Number
- linux内核官方网站
- JAXB--@XmlElementWrapper注解(二)
- 009.BOOL 布尔类型
- 项目设置笔记
- Centos 5.6下rsync安装配置(yum)
- Linux驱动修炼之道-SPI驱动框架源码分析(下)
- 在 KitKat以上版本中使用Translucent将Navigation Bar透明化
- C++设计模式(一) 工厂模式