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.

    Input:Digit string "23"
    Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].

    gave digits = "23"

    i=0 -> result=combine("abc", [""]) ---> [a,b,c];

    i=1 -> result=combine("def", [a,b,c]) ---> [ad,bd,cd, ae,be,ce, af,bf,cf];

     1   public class Solution {
     2         public static List<String> letterCombinations(String digits) {
     3             String digitletter[] = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
     4             List<String> result = new ArrayList<String>();
     5 
     6             if (digits.length()==0) return result;
     7 
     8             result.add("");
     9             for (int i=0; i<digits.length(); i++) 
    10                 result = combine(digitletter[digits.charAt(i)-'0'],result);
    11 
    12             return result;
    13         }
    14 
    15         public static List<String> combine(String digit, List<String> list) {
    16             List<String> result = new ArrayList<String>();
    17 
    18             for (int i=0; i<digit.length(); i++) 
    19                 for (String x : list) 
    20                     result.add(x+digit.charAt(i));
    21 
    22             return result;
    23         }
    24     }
  • 相关阅读:
    云计算安全概述
    快照技术
    存储可靠性技术之--备份
    存储可靠性技术之 --RAID
    存储方式
    存储技术
    CentOS安装setup
    CentOS7安装iptables防火墙
    CentOS 7.0下使用yum安装MySQL
    The APR based Apache Tomcat Native library
  • 原文地址:https://www.cnblogs.com/hygeia/p/4970619.html
Copyright © 2011-2022 走看看