leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0017.cpp (471B)


      1 class Solution {
      2   public:
      3     vector<string> letterCombinations(string digits) {
      4         vector<string> um = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}, res = {""};
      5 
      6         for (char d : digits) {
      7             vector<string> tmp;
      8             for (char l : um[d - '2'])
      9                 for (const string &s : res)
     10                     tmp.push_back(s + l);
     11             res = tmp;
     12         }
     13 
     14         return res.size() > 1 ? res : vector<string>();
     15     }
     16 };