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. [Python]查询mysql导出结果至Excel并发送邮件

    环境:Linux +python2.7+mysql5.6 1.提前安装xlwt(excel写入操作模块),MySQLdb(mysql操作模块) 2.脚本如下: #!/usr/bin/python #c ...

  2. uiautomator:Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!

    尝试用android sdk的uiautomatorviewer抓元素的时候报错:Error while obtaining UI hierarchy XML file: com.android.dd ...

  3. 关于 Level 和 Promotion,其实就那么简单

    曾经有读者和朋友问我:一般硅谷工作了三四年以后,会是什么 level?找工作会拿到什么 package?拿到这个问题之后,我想了想,还是没有回答.其实三四年的时间,对于曾经在同一个起点的两个人,因为际 ...

  4. 机器学习进阶-图像形态学变化-礼帽与黑帽 1.cv2.TOPHAT(礼帽-原始图片-开运算后图片) 2.cv2.BLACKHAT(黑帽 闭运算-原始图片)

    1.op = cv2.TOPHAT  礼帽:原始图片-开运算后的图片 2. op=cv2.BLACKHAT 黑帽: 闭运算后的图片-原始图片 礼帽:表示的是原始图像-开运算(先腐蚀再膨胀)以后的图像 ...

  5. Scrapy框架--代理和cookie

    如何发起post请求? 代理和cookie: cookie:豆瓣网个人登录,获取该用户个人主页这个二级页面的页面数据. 如何发起post请求? 一定要对start_requests方法进行重写. 1. ...

  6. Redis学习笔记一(Redis的详细安装及Linux环境变量配置和启动)

     Redis Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. 我使用的是下面这个版本: 若没有资源的话,我在 ...

  7. 4:list 列表

    list:列表.数组.array . list 是有序的,list的定义以 [] 为标识.如:list1 = ['name1', 'name2', 'name3'] 元素可以是任何类型的,如字符串.数 ...

  8. [C语言]数据类型与计算

    ------------------------------------------------------------------------------------------------- 实际 ...

  9. IPv4和IPv6的差异;如何实现IPv4和IPv6双协议栈的通信

    1 IPv4和IPv6的差异 1.1 地址空间   IPv6 与 IPv4 比较最显著的一个改动就是使用 128 比特上的地址来代替了 32 比特长的 IPv4 地址. IPv6 中取消了广播地址, ...

  10. reids遇到问题

    今天重启爬虫服务器在连接redis数据库时突然报错:MISCONF Redis is configured to save RDB snapshots, but it is currently not ...