zoukankan      html  css  js  c++  java
  • Letter Combinations of a Phone Number

    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.

    msg

    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.

    public List<String> letterCombinations(String digits) {
            List<String> result = new ArrayList<>();
            String[] dic = new String[]{"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
            Combinations(digits,0,result,"",dic);
            return result;
        }
        private void Combinations(String digits,int index,List<String> result,String curr,String[] dic){
            if (index==digits.length()){
                if (curr.length()!=0) result.add(curr);
                return;
            }
            String temp = dic[digits.charAt(index)-'0'];
            for (int i=0;i<temp.length();i++){
                String next = curr + temp.charAt(i);
                Combinations(digits,index+1,result,next,dic);
            }
        }
    
  • 相关阅读:
    Dapper的常用操作
    git下载慢的解决方案
    笔记
    第06组 Beta冲刺(3/5)
    第06组 Beta冲刺(2/5)
    第06组 Beta冲刺(1/5)
    第06组 Alpha事后诸葛亮
    第06组 Alpha冲刺(6/6)
    第06组 Alpha冲刺(5/6)
    第06组 Alpha冲刺(4/6)
  • 原文地址:https://www.cnblogs.com/bingo2-here/p/7603785.html
Copyright © 2011-2022 走看看