LeetCode 017 Letter Combinations of a Phone Number
来源:互联网 发布:aft3登陆器源码 编辑:程序博客网 时间:2024/05/29 15:35
字符串按照zigzag排列,最后按照行输出结果。
public static List<String> letterCombinations(String digits) { List<String> ans = new ArrayList<String>(); if(digits == null || digits.length() == 0){ return ans; } String[] record = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; StringBuffer sb = new StringBuffer(); useme(ans,record,digits,0,sb); return ans; } public static void useme(List<String> ans, String[] record, String digits, int index,StringBuffer sb){ if(index == digits.length()){ ans.add(new String(sb)); return ; } String curStr = record[digits.charAt(index)-'0']; if(curStr.equals("")){ useme(ans,record,digits,index+1,sb); } for(int i =0;i<curStr.length();i++){ char curChar = curStr.charAt(i); sb.append(curChar); useme(ans,record,digits,index+1,sb); sb.deleteCharAt(sb.length()-1); } }
要注意 0,1 的时候,可能进入不了循环,所以要加一个判断,直接跳过他们。
0 0
- LeetCode: Letter Combinations of a Phone Number
- LeetCode Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- [Leetcode] Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- 【leetcode】Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- [LeetCode]Letter Combinations of a Phone Number
- LeetCode-Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- LeetCode - Letter Combinations of a Phone Number
- LeetCode:Letter Combinations of a Phone Number
- LeetCode | Letter Combinations of a Phone Number
- leetcode Letter Combinations of a Phone Number
- Leetcode: Letter Combinations of a Phone Number
- 【leetcode】Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- leetcode: Letter Combinations of a Phone Number
- 试着用物理学第一原理思考问题
- poj 2947 Widget Factory (高斯消元)
- enum——枚举类型解析
- Android下拉刷新完全解析,教你如何一分钟实现下拉刷新功能
- STC15F2K60S2烧写程序时卡在开始调节频率处,下载失败
- LeetCode 017 Letter Combinations of a Phone Number
- IOS微博项目之UIScrollView&UIPageControl
- 教训 : 公用模块修改要注意,能添加的就不要修改
- [leetcode]Populating Next Right Pointers in Each Node II
- UVa 10603 倒水
- iOS/Xcode 自动生成注释
- centos 用户和组,权限,添加删除详解
- 程序员在互联网公司和行业软件公司工作,有什么区别?
- Linux下select, poll和epoll IO模型的详解