leetcode 17 letter combinations of a phone number

OJ address

Leetcode website : 17. Letter Combinations of a Phone Number

Description

Given a string containing digits from 2-9 inclusive, 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. Note that 1 does not map to any letters.

image

Example:

Input: “23”
Output: [“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf”].

My Solution in C


#include <stdlib.h>
#include <string.h>

int indexValue = 0;

void (const char *s ,char** letter_matrix, int count, int n, char **returnArray, char *newArray);

char** letterCombinations(char* digits, int* returnSize) {
if (!strlen(digits)) {
*returnSize = 0;
return 0;
}
indexValue = 0;
char *letter_matrix[10];
letter_matrix[0] = " ";
letter_matrix[1] = " ";
letter_matrix[2] = "abc";
letter_matrix[3] = "def";
letter_matrix[4] = "ghi";
letter_matrix[5] = "jkl";
letter_matrix[6] = "mno";
letter_matrix[7] = "pqrs";
letter_matrix[8] = "tuv";
letter_matrix[9] = "wxyz";
char *s = malloc(sizeof(char) * strlen(digits));
memset(s, '