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

Letter Combinations of a Phone Number

时间:2015-01-17 11:08:41      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

class Solution {
public:
   vector<string> result;
    vector<string> letterCombinations(string digits) {
	 string buf[] = {
	    "abc","def","ghi","jkl","mno","pqrs","tuv","wxyz",
	    };
	  
      if(digits.empty())
      {
        result.push_back("");
        return result;
	  }
      
      string combin;
	  combin.resize(digits.size());
	  GetCombinations(buf,digits,combin);
	  return result;
    }
    void GetCombinations(string buf[],string digits,string& combin)
    {
      if(digits.empty())
      {
         result.push_back(combin);
         return ;
	  }
	  if(digits[0]<‘2‘||digits[0]>‘9‘)
	  	return ;
	  int index = digits[0] - ‘2‘;
	  int len = digits.size();
	  len = combin.size()-len;
	  for(int i=0;i<buf[index].size(); i++)
	  {
         combin[len]=buf[index][i];
		 GetCombinations(buf,digits.substr(1,-1),combin);
	  }


	}

	
};

  

Letter Combinations of a Phone Number

标签:

原文地址:http://www.cnblogs.com/xgcode/p/4230201.html

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