上一页 1 ··· 9 10 11 12 13
摘要: 这个题目比较要注意的一点是如何防止重复。在dfs中,下一层的因子应该大于等于上一层的public class Solution { List> result = new ArrayList>(); public List> getFactors(int n) { if (n... 阅读全文
posted @ 2015-11-26 16:23 Weizheng_Love_Coding 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 先吐槽一下这个题目,和他的名字一样丑陋。我真的不知道这个题对于一个程序员的考点在哪里,也不知道是不是在45分钟的面试中,第一次碰到这个题目想不出这个解法就能说明这个程序员不好? 感觉完全的奥数式题目(1) 1×2, 2×2, 3×2, 4×2, 5×2, …(2) 1×3, 2×3, 3×3, 4×... 阅读全文
posted @ 2015-11-26 16:10 Weizheng_Love_Coding 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 我用的拓扑排序,思路类似外星人语言那道题public class Solution { public List findMinHeightTrees(int n, int[][] edges) { HashMap in_degree = new HashMap(); ... 阅读全文
posted @ 2015-11-26 15:04 Weizheng_Love_Coding 阅读(486) 评论(0) 推荐(0) 编辑
摘要: 挺经典的拓扑排序,注意的就是最后判断是否合法的判据是所有入度都为0public class Solution { public String alienOrder(String[] words) { HashMap> map = new HashMap>(); Ha... 阅读全文
posted @ 2015-11-26 14:43 Weizheng_Love_Coding 阅读(124) 评论(0) 推荐(0) 编辑
摘要: Boringpublic class Solution { public TreeNode inorderSuccessor(TreeNode root, TreeNode p) { return helper(root, p, null); } public Tre... 阅读全文
posted @ 2015-11-26 13:18 Weizheng_Love_Coding 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 注意读题,不能改变相对顺序。小trick是 p1 == p2时候 不能给p2变成0了。public class Solution { public void moveZeroes(int[] nums) { int p1 = 0; int p2 = 0; ... 阅读全文
posted @ 2015-11-26 09:27 Weizheng_Love_Coding 阅读(76) 评论(0) 推荐(0) 编辑
摘要: 没啥好说的,注意用long(明明题目里说integer,汗)public class Solution { public boolean isAdditiveNumber(String num) { int length = num.length(); int i ... 阅读全文
posted @ 2015-11-26 09:17 Weizheng_Love_Coding 阅读(175) 评论(0) 推荐(0) 编辑
摘要: dfs, 思路就是对于加减法直接操作,但是对于乘法,要保留做乘法之前的值比如 输入是1322假设已经到了1 + 3,我们想尝试1 + 3 * 2,这时如果直接用2 * 4则会出错,所以我们与4同时传入的参数还应该有上一步操作之前的值,即为1. 当我们采用乘法时,应该用(4 - 1) * 2 + 1作... 阅读全文
posted @ 2015-11-26 08:50 Weizheng_Love_Coding 阅读(139) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public int hIndex(int[] citations) { int length = citations.length; int[] record = new int[length + 1]; ... 阅读全文
posted @ 2015-11-26 07:52 Weizheng_Love_Coding 阅读(115) 评论(0) 推荐(0) 编辑
上一页 1 ··· 9 10 11 12 13