赞
踩
题目
解法
①数组, 字符串 + 循环, 递归
class Solution { String[] map = { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" }; List<String> ret = new ArrayList<>(); public List<String> letterCombinations(String digits) { if(digits.length() == 0){ return ret; } char[] track = new char[digits.length()]; trackback(track, digits, 0); return ret; } public void trackback(char[] track, String digits, int num){ if(num == digits.length()){ ret.add(new String(track)); return; } char[] ch = map[digits.charAt(num) - '0'].toCharArray(); for(char c : ch){ track[num] = c; trackback(track, digits, num + 1); } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。