摘要: public class Solution { public int missingNumber(int[] nums) { int n = 0; for (int num : nums) { n = Math.max(n, num); ... 阅读全文
posted @ 2015-11-28 15:38 Weizheng_Love_Coding 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 先找到两个cand在某一位不相同, 在分别异或public class Solution { public int[] singleNumber(int[] nums) { int tmp = nums[0]; for (int i = 1; i < nums.le... 阅读全文
posted @ 2015-11-28 15:33 Weizheng_Love_Coding 阅读(82) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public int shortestWordDistance(String[] words, String word1, String word2) { int pre1 = -1; int pre2 = -1; ... 阅读全文
posted @ 2015-11-28 09:44 Weizheng_Love_Coding 阅读(126) 评论(0) 推荐(0) 编辑
摘要: public class WordDistance { private HashMap> map = new HashMap>(); public WordDistance(String[] words) { for (int i = 0; i list = map.co... 阅读全文
posted @ 2015-11-28 09:33 Weizheng_Love_Coding 阅读(132) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public List majorityElement(int[] nums) { int can1 = 0, can2 = 0, num1 = 0, num2 = 0; for (int num : nums) { ... 阅读全文
posted @ 2015-11-28 09:07 Weizheng_Love_Coding 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 这个题目考点在于矩阵中有很多0的时候怎么处理。我是创建了一个Node的数据结构,分别存index和值。看网上有个小哥是把index和值分别存在 i 和i + 1 的位置,感觉也很好,不过算法复杂度本质没有变化。public class Solution { public int[][] mul... 阅读全文
posted @ 2015-11-28 08:39 Weizheng_Love_Coding 阅读(124) 评论(0) 推荐(0) 编辑