首页 > 其他 > 详细

Letter Combinations of a Phone Number

时间:2015-01-17 11:06:20      阅读:225      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!