LeetCode Letter Combinations of a Phone Number C++
来源:互联网 发布:阿里云 协会 备案 编辑:程序博客网 时间:2024/06/05 15:05
#include <iostream>#include <vector>#include<algorithm>#include <queue>using namespace std;/************************************************************************//*Problem: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.For example: 1 2 3 abc edf 4 5 6 ghi jkl mno 7 8 9 pqrs tuv wxzy Input:Digit string "23" Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].Author : crazys_popcorn@126.comDateTime: 2017年8月5日 12:06:17*//************************************************************************/class Solution {public: vector<string> letterCombinations(string digits) { vector<string>_result; if (digits.size() < 1) return _result; //定义9个按钮 vector<string>_zinum = {"", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxzy" }; int _size = digits.size(); _result.push_back(""); for (int i = 0; i < _size; i++) { int num = digits[i] - '1'; if (num <1 || num > 9) continue; std::string& _str = _zinum[num]; if (_str.empty()) continue; std::vector<string > _tempresult; for (int j = 0; j < _str.size(); ++j) { for (int k = 0; k<_result.size(); ++k) { //按照顺序相加 双层for循环。。把每一个for的第一个字母 宇第二组字母都相加插入到新的容器里面 //然后swap 交换。 _tempresult.push_back(_result[k] + _str[j]); } } _result.swap(_tempresult); } return _result; }};void main(){ std::string _str = "2"; Solution s1; vector<string>_nums; _nums = s1.letterCombinations(_str); std::cout << "" << endl; system("pause");}
阅读全文
0 0
- [C++]LeetCode: 87 Letter Combinations of a Phone Number
- 【C++】【LeetCode】17. 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
- 起点
- matplotlib一些常用知识点
- tomcat 配置成window服务后设置jvm内存
- BigDecimal
- Oracle基础教程-第六章 模式对象
- LeetCode Letter Combinations of a Phone Number C++
- eclipse下重置窗口布局
- 简单计算器实现含源码。
- 给小白揭秘你想知道的UI设计工作
- C++----友元
- nginx 修改配置重新加载命令
- pat 1068. 万绿丛中一点红易错点解析
- laravel 验证码刷新
- * 24种设计模式——享元模式