package q17 var alphabets = [][]byte{ []byte("abc"), []byte("def"), []byte("ghi"), []byte("jkl"), []byte("mno"), []byte("pqrs"), []byte("tuv"), []byte("wxyz"), } func combinations(offsets []int, i int, buffer []byte, strings []string) []string { if buffer == nil { buffer = make([]byte, len(offsets)) } if i == len(offsets) { return append(strings, string(buffer)) } for _, c := range alphabets[offsets[i]] { buffer[i] = c strings = combinations(offsets, i+1, buffer, strings) } return strings } func letterCombinations(digits string) []string { offsets := make([]int, len(digits)) for i := range len(digits) { offsets[i] = int(digits[i] - '2') } return combinations(offsets, 0, nil, []string{}) } var _ = letterCombinations