码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode#17 Letter Combinations of a Phone Number

时间:2015-01-30 17:28:38      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

原题地址

 

简单DFS题目

 

代码:

 1 vector<string> res;
 2     
 3 void dfs(string &digits, vector<string> &i2s, string ans, int pos) {
 4   if (pos == digits.length()) {
 5     res.push_back(ans);
 6     return;
 7   }
 8         
 9   for (auto c : i2s[digits[pos] - 0])
10     dfs(digits, i2s, ans + c, pos + 1);
11 }
12 
13 vector<string> letterCombinations(string digits) {
14   vector<string> i2s {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
15   dfs(digits, i2s, "", 0);
16   return res;
17 }

 

Leetcode#17 Letter Combinations of a Phone Number

标签:

原文地址:http://www.cnblogs.com/boring09/p/4262510.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!