您的当前位置:首页正文

17. Letter Combinations of a Phone Number

2024-11-10 来源:个人技术集锦
public class Solution {
    public List<String> letterCombinations(String digits) {
        LinkedList<String> que=new LinkedList<String>();
        if(digits.length()==0)
            return que;
        String[] btns=new String[]{"0","1","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
        que.add("");
        for(int i=0;i<digits.length();i++)
        {
            String btn=btns[digits.charAt(i)-'0'];
            while(que.peek().length()==i)
            {
                String item=que.poll();
                for(int j=0;j<btn.length();j++)
                    que.add(item+btn.charAt(j));
            }
        }
        return que;
    }
}

 

转载于:https://www.cnblogs.com/asuran/p/7578732.html

Top