zoukankan      html  css  js  c++  java
  • Leetcode 17

    //狂练回溯,巧用备胎
    class
    Solution { public: vector<string> letterCombinations(string digits) { vector<string> res; if(digits == "") return res; string add; DFS(res,add,digits,0); return res; } void DFS(vector<string>& res,string add,string digits,int pos){ if(pos == digits.size()){ res.push_back(add); return; } else{ string temp; int t = digits[pos]-'0'; if(t == 2) temp = "abc"; else if(t == 3)temp = "def"; else if(t == 4)temp = "ghi"; else if(t == 5)temp = "jkl"; else if(t == 6)temp = "mno"; else if(t == 7)temp = "pqrs"; else if(t == 8)temp = "tuv"; else if(t == 9)temp = "wxyz"; for(int i=0;i < temp.size();i++){ string beitai= add+temp[i]; //巧用备胎!! DFS(res,beitai,digits,pos+1); } } } };
  • 相关阅读:
    中风后遗症
    慢性湿疹半年
    女子脚背痒肿案
    肾盂肾炎病案
    鼻衄二则
    糖尿病病案
    慢性肠炎2例
    子宫肌瘤病案2例
    眩晕病案
    前列腺炎病案3例
  • 原文地址:https://www.cnblogs.com/cunyusup/p/9878026.html
Copyright © 2011-2022 走看看