*LeetCode-Letter Combinations of a Phone Number
来源:互联网 发布:有关孙悟空的网络电影 编辑:程序博客网 时间:2024/05/16 12:23
错好多
recursive的下次再写吧
最严重的错误就是 每次循环想要把原来list里面每个string都加一个字母的时候 注意list要重新建 不能for each str in list 然后再里面又在这同一个list上面操作
public class Solution { public List<String> letterCombinations(String digits) { List<String> res = new ArrayList<String>(); List<String> nums = Arrays.asList("0","1","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"); if ( digits == null || digits.length() == 0 ) return res; res.add(""); for ( int i = 0; i < digits.length(); i ++ ){ List<String> temp = new ArrayList<String>(); for ( String str : res ){ int num = digits.charAt(i) - '0'; int end = 3; if ( num == 7 || num == 9 ) end = 4; for ( int j = 0; j < end; j ++ ){ String tempstr = str + nums.get(num).charAt(j); temp.add(tempstr); } } res = temp; } return res; }}
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
- php检测字符串是否含有重复或递增的字符
- GLUT 调用回调函数API的理解与小结
- 分布式设计与开发(二)------几种必须了解的分布式算法
- 【傻傻分不清楚】C#值类型、引用类型
- Aspx网页画图
- *LeetCode-Letter Combinations of a Phone Number
- Android开发艺术探索读书笔记(二)
- 利用RunTrace实时跟踪分析iOS App视图
- UTF8与GBK间的转换
- 红黑树----红黑树插入和删除结点的全程演示
- 设计模式之外观模式Facade(结构型)
- 网站安全退出后,再点击浏览器后退按钮不能返回前一个页面的笨办法
- shell脚本学习 二
- mybatis二级缓存应用及与ehcache整合