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

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

题目连接

  

Letter Combinations of a Phone Number

Description

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

Note:

Although the above answer is in lexicographical order, your answer could be in any order you want.

dfs。。

class Solution {public:	vector
letterCombinations(string digits) { init(); ans.clear(); n = digits.length(); if (!n) return ans; dfs(0, "", digits); return ans; }private: size_t n; map
A; vector
ans; void init() { A[2] = "abc"; A[3] = "def"; A[4] = "ghi"; A[5] = "jkl"; A[6] = "mno"; A[7] = "pqrs"; A[8] = "tuv"; A[9] = "wxyz"; } void dfs(int cur, string x, string digits) { if (cur == n) { ans.push_back(x); return; } int d = digits[cur] - '0'; for (size_t i = 0; i < A[d].size(); i++) { dfs(cur + 1, x + A[d][i], digits); } }};

转载于:https://www.cnblogs.com/GadyPu/p/5040247.html

你可能感兴趣的文章
[转]免费api大全
查看>>
git 认证问题之一的解决 : http ssh 互换
查看>>
sql where 1=1作用
查看>>
搜索算法----二分查找
查看>>
Python语言编程
查看>>
[poj 1469]Courses
查看>>
vue+element-ui实现表格checkbox单选
查看>>
测试开发学习进阶教程 视频&PDF
查看>>
C#基础-连接Access与SQL Server
查看>>
autofac
查看>>
MacOS 系统终端上传文件到 linux 服务器
查看>>
Excel导出POI
查看>>
兼容性
查看>>
自动执行sftp命令的脚本
查看>>
转 Merkle Tree(默克尔树)算法解析
查看>>
网络编程基础之socket编程
查看>>
各种浏览器的user-agent和
查看>>
Restful levels
查看>>
Phonegap移动开发:布局总结(一) 全局
查看>>
Java 变参函数的实现
查看>>