(java)leetcode-17

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"].

Note:
Although the above answer is in lexicographical order, your answer could be in any order you want.


解题思路:

这道题,大概就是将string转为int,然后找到对应的字符串进行添加就好了。

大概就是一个组合的东西,我也没想到什么简要的办法,所以就不断循环添加。


public class Solution {
    public List letterCombinations(String digits) {
        String[] ans = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
        List result = new ArrayList();
        if(digits == "" || digits.length() == 0)
        	return result;
        result.add("");
        int[] num = new int[digits.length()];
        for(int i = 0;i midans = new ArrayList();
        	String s1 = ans[num[k]];
        	for(int i = 0;i


你可能感兴趣的:(leetcode)