17. Letter Combinations of a Phone Number (backtracking)
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)的更多相关文章
- [LeetCode][Python]17: Letter Combinations of a Phone Number
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...
- 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 ...
- 刷题17. Letter Combinations of a Phone Number
一.题目说明 题目17. Letter Combinations of a Phone Number,题目给了下面一个图,输入一个字符串包括2-9,输出所有可能的字符组合. 如输入23所有可能的输出: ...
- 《LeetBook》leetcode题解(17):Letter Combinations of a Phone Number[M]
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- [leetcode]17. Letter Combinations of a Phone Number手机键盘的字母组合
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that th ...
- [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合
Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...
- 17. Letter Combinations of a Phone Number
题目: Given a digit string, return all possible letter combinations that the number could represent. A ...
- [leetcode 17]Letter Combinations of a Phone Number
1 题目: Given a digit string, return all possible letter combinations that the number could represent. ...
- Java [leetcode 17]Letter Combinations of a Phone Number
题目描述: Given a digit string, return all possible letter combinations that the number could represent. ...
随机推荐
- js 简单算法
1. 嵌套数组打平并且去重 ,,,,,,,,[,,,,[,,]]]; var obj = {};//去重标识 function test(data) { var newArr = []; for ( ...
- CKEditor 5
1.官网 https://ckeditor.com/ckeditor-5/download/ 2.
- golang 字符串截取
java中有SubString,那golang怎么截取字符串? str := "hello world" fmt.Print(str[:]) 以上代码输出 hello 数组,sli ...
- python day10 数据库(mysql基础)
一.数据库的概念 数据:事物的特征 数据库的本质是:通过套接字进行通信,来读存数据的一种软件,由于每次开发人员写程序都得写数据的套接字,所以诞生了数据库这个软件,减少重复劳动.(sql语句通用) 数据 ...
- beyondCompare工具使用
1.下载beyondcompare (从官网下载) 2.载入.class文件比对 参见: beyond compare 对class文件反编译及比较 (https://blog.csdn.net/ ...
- 跟我一起学Python-day1(条件语句以及初识变量)
通过练习题来学习条件语句 1,使用while循环输出1 2 3 4 5 6 8 9 10 n=1 while n<11: if n=7: pass else: print(n) n=n ...
- python中time模块和datetime模块
time模块和datetime模块 时间分为三种模式(time 模块) 时间戳 (time.time()) 格式化字符串 (time.strftime(%Y-%m-%d %H:%M:%S %p)) ...
- C++17尝鲜:变长 using 声明
using 声明 先来看 using 声明在类中的应用: 代码1 #include <iostream> using namespace std; struct A { void f(in ...
- ORACLE常用操作命令
1.ORACLE实例启动.停止 SQL>startup; #启动ORACLE实例 SQL>shutdown immediate; #关闭ORACLE实例,常用.阻止新用户连接且阻止已连接 ...
- 收藏点webservice接口
商业和贸易: 1.股票行情数据 WEB 服务(支持香港.深圳.上海基金.债券和股票:支持多股票同时查询) Endpoint: http://webservice.webxml.com.cn/WebSe ...