博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode_Letter Combinations of a Phone Number
阅读量:4334 次
发布时间:2019-06-07

本文共 1274 字,大约阅读时间需要 4 分钟。

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"].

  水题: DFS

int counts[] = {
0, 0, 3, 3, 3, 3, 3, 4, 3, 4}; char letter[] = {
'0', '0', 'a', 'd', 'g', 'j', 'm', 'p', 't', 'w'}; class Solution {public: void DFS( string & digit,int i, string s) { if(i == size){ result.push_back(s); return ; } int index = digit[i] - '0' ; for(int j = 0; j < counts[index] ; j++) { char c = letter[index]+j ; DFS(digit, i+1, s+c); } } vector
letterCombinations(string digits) { // Start typing your C/C++ solution below // DO NOT write int main() function result.clear(); size = digits.size(); string s = ""; DFS(digits, 0 , s); return result ; }private :vector
result ;int size ;};

 

转载于:https://www.cnblogs.com/graph/p/3213036.html

你可能感兴趣的文章
spring第二冲刺阶段第七天
查看>>
搜索框键盘抬起事件2
查看>>
阿里百川SDK初始化失败 错误码是203
查看>>
透析Java本质-谁创建了对象,this是什么
查看>>
BFS和DFS的java实现
查看>>
关于jquery中prev()和next()的用法
查看>>
一、 kettle开发、上线常见问题以及防错规范步骤
查看>>
eclipse没有server选项
查看>>
CRC码计算及校验原理的最通俗诠释
查看>>
QTcpSocket的连续发送数据和连续接收数据
查看>>
使用Gitbook来编写你的Api文档
查看>>
jquery扩展 $.fn
查看>>
Markdown指南
查看>>
influxDB的安装和简单使用
查看>>
JPA框架学习
查看>>
JPA、JTA、XA相关索引
查看>>
机器分配
查看>>
php opcode缓存
查看>>
springcloud之Feign、ribbon设置超时时间和重试机制的总结
查看>>
观看杨老师(杨旭)Asp.Net Core MVC入门教程记录
查看>>