leetcode:Letter Combinations of a Phone Number [17]

    xiaoxiao2025-07-26  9

    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; } };

    转载请注明原文地址: https://ju.6miu.com/read-1301097.html
    最新回复(0)