17. Letter Combinations of a Phone Number

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;
    }
}

 

posted @ 2017-09-23 01:11  Weiyu Wang  阅读(135)  评论(0编辑  收藏  举报