Monogram Lc17- phone number











 
public class Lc17 {
    public static List<String> letterCombinations(String digits) {
        // 避免频繁扩容
        LinkedList<String> ans = new LinkedList<String>();
        String[] mapping = new String[] { "0", "1", "abc", "def", "ghi", "jkl", "mno", "PQRS " , " TUV " , " wxyz " }; 

        // null Analyzing 
        IF (digits.length () == 0 ) {
             return  new new the ArrayList <> (); 
        } 
        // This is the characteristic of the use of the queue is traversed bfs 
        ans. the Add ( "" );
         // not knowing particularly how many digits, so that for a control 
        for ( int I = 0 ; I <digits.length (); I ++ ) {
             // find the corresponding number, such as input 23, found or 2. 3 
            int X = Character.getNumericValue (digits.charAt (I));
            / * 
             * When the 0th cycle, the length of the space-time element in the queue, i.e. 0 
             * when the first cycle, the length of the element in the queue a / b / c, i.e. a. And so on 
             * / 
            the while (. Ans.peek () length () == I) {
                 // get the elements in the queue, and removing the element recombined 
                String T = ans.remove ();
                 for (CH Character: Mapping [X] .toCharArray ()) { 
                    ans.add (T + CH); 
                } 
            } 
        } 
        return ANS; 
    } 

    public  static  void main (String [] args) { 
        String digits = " 23 is " ;
        System.out.println(letterCombinations(digits));
    }
}

Guess you like

Origin www.cnblogs.com/xiaoshahai/p/12182608.html