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"].
/**
* Return an array of size *returnSize.
* Note: The returned array must be malloced, assume caller calls free().
*/
char* digit2Letter(char digit){
switch(digit){
case '':
return "abc";
case '':
return "def";
case '':
return "ghi";
case '':
return "jkl";
case '':
return "mno";
case '':
return "pqrs";
case '':
return "tuv";
case '':
return "wxyz";
default:
return "";
}
} char** letterCombinations(char* digits, int* returnSize) {
char** returnArray = NULL;
if(*digits == '\0') return returnArray; char* returnElem = malloc(sizeof(char)*sizeof(strlen(digits)));
returnArray = malloc(sizeof(char*)*);
backTracking(digits, returnArray, returnSize, returnElem, ); return returnArray;
} void backTracking(char* digits, char** returnArray, int* returnSize, char* returnElem, int pElem){
if(*digits == '\0'){
(*returnSize)++;
char* elem = malloc(sizeof(char)*pElem);
memcpy(elem, returnElem, sizeof(char)*pElem);
elem[pElem] = '\0';
printf("elem[0] = %d, elem[1] = %d\n",elem[],elem[]);
returnArray[*returnSize-] = elem;
return;
} char* str = digit2Letter(*digits);
int len = strlen(str);
for(int i = ; i < len; i++){
returnElem[pElem] = str[i]; backTracking(digits+, returnArray, returnSize, returnElem, pElem+ );
}
}

17. Letter Combinations of a Phone Number (backtracking)的更多相关文章

  1. [LeetCode][Python]17: Letter Combinations of a Phone Number

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...

  2. Leetcode 17. Letter Combinations of a Phone Number(水)

    17. Letter Combinations of a Phone Number Medium Given a string containing digits from 2-9 inclusive ...

  3. 刷题17. Letter Combinations of a Phone Number

    一.题目说明 题目17. Letter Combinations of a Phone Number,题目给了下面一个图,输入一个字符串包括2-9,输出所有可能的字符组合. 如输入23所有可能的输出: ...

  4. 《LeetBook》leetcode题解(17):Letter Combinations of a Phone Number[M]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

  5. [leetcode]17. Letter Combinations of a Phone Number手机键盘的字母组合

    Given a string containing digits from 2-9 inclusive, return all possible letter combinations that th ...

  6. [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合

    Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...

  7. 17. Letter Combinations of a Phone Number

    题目: Given a digit string, return all possible letter combinations that the number could represent. A ...

  8. [leetcode 17]Letter Combinations of a Phone Number

    1 题目: Given a digit string, return all possible letter combinations that the number could represent. ...

  9. Java [leetcode 17]Letter Combinations of a Phone Number

    题目描述: Given a digit string, return all possible letter combinations that the number could represent. ...

随机推荐

  1. centos下查看python的安装目录

    直接用python命令,打印sys的path即可: >>> import sys >>> print(sys.path) ['', '/usr/local/lib/ ...

  2. 机器学习入门-数值特征-进行多项式变化(将特征投影到高维度上) 1.PolynomialFeatures(将数据变化为多项式特征)

    函数说明: 1. PolynomialFeatures(degree=2, interaction_only=False, include_bias=False) 参数说明:degree=2,表示多项 ...

  3. block原理

    block原理 block的本质是一个结构体,包含引用的外部变量及一个需要执行的函数的函数指针,在内存中可以有三个位置,即堆上.栈上和全局区(静态区).当block中没有引用外部变量时,block的位 ...

  4. python tuple排序

    tuple排序,按照索引0,1,2,3...依次比较 a = [3,1,0,9,6,2,4,8,7,5] a.sort(key = lambda x: (x%2, x, x%3)) # 先按照x%2的 ...

  5. 使用pt-table-checksum及pt-table-sync校验复制一致性

    一.简介 pt-table-checksum是percona-toolkit系列工具中的一个, 可以用来检测主. 从数据库中数据的一致性.其原理是在主库上运行, 对同步的表进行checksum, 记录 ...

  6. Python在cmd上打印彩色文字

    在Windows上编写python程序时,有时候需要对输出的文字颜色进行设置,特别是日志显示,不同级别的日志设置不同的颜色进行展示可以直观查看.本文主要描述通过ctypes.windll.kernel ...

  7. Windows常用命令实例

    熟练使用DOS常用命令有助于提高工作效率. 1.windows+R:打开运行程序窗口 2.cmd:调用DOS命令窗口 3.mstsc:调用远程桌面命令窗口.mstsc -v 192.168..0.1 ...

  8. CHAR 和VARCHAR的区别

    CHAR(10)是不可变长度为10的字符串,占的存储空间始终为10个字符的长度,而VARCHAR(10)是可变长度的字符串,故而可以节省空间.例如:储存"aaaaabbbbb",则 ...

  9. spring boot 集成Thymeleaf

                                           

  10. shiro 密码的MD5盐值加密