leetcode:Letter Combinations of a Phone Number [17]

来源:互联网 发布:数据库qps 编辑:程序博客网 时间:2024/05/03 21:03

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"].

class Solution {public:void pu(string digits, int i, vector<string> *a) {if (i == digits.length() - 1) {}}vector<string> letterCombinations(string digits) {string a[11] = { "","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz" };vector<string> s1;deque<string> deq;if (digits.empty()) return s1;string s;for (int i = 0; i < a[digits[0] - '0'].length(); i++) {s = s + a[digits[0] - '0'][i];deq.push_back(s);s = "";}while (deq[0].length() < digits.length()) {string t = "";for (int i = 0; i < a[digits[deq[0].length()] - '0'].length(); i++) {deq.push_back(deq[0] + a[digits[deq[0].length()] - '0'][i]);}deq.pop_front();}for (int i = 0; i < deq.size(); i++) {s1.push_back(deq[i]);}return s1;}};




0 0
原创粉丝点击