#include "s0017_letter_combinations_of_a_phone_number.hpp" vector S0017::letterCombinations(string digits) { unordered_map> map; map["2"] = vector{"a", "b", "c"}; map["3"] = vector{"d", "e", "f"}; map["4"] = vector{"g", "h", "i"}; map["5"] = vector{"j", "k", "l"}; map["6"] = vector{"m", "n", "o"}; map["7"] = vector{"p", "q", "r", "s"}; map["8"] = vector{"t", "u", "v"}; map["9"] = vector{"w", "x", "y", "z"}; if (digits.length() == 0) { return vector{}; } else { string last = digits.substr(digits.length() - 1, 1); digits.pop_back(); vector combinations = letterCombinations(digits); if (combinations.size() == 0) { combinations = {""}; } vector result = {}; for (int i{0}; i < map.at(last).size(); i++) { vector temp = combinations; for (int j{0}; j < temp.size(); j++) { temp[j] += map.at(last)[i]; } result.insert(result.end(), temp.begin(), temp.end()); } return result; } }