上一页 1 ··· 7 8 9 10 11 12 13 下一页
摘要: 二分搜索public class Solution { public int hIndex(int[] citations) { int length = citations.length; if (length == 0) { return ... 阅读全文
posted @ 2015-11-29 06:56 Weizheng_Love_Coding 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 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) 编辑
摘要: public class Solution { TreeNode result = new TreeNode(0); public int kthSmallest(TreeNode root, int k) { helper(root, k); return ... 阅读全文
posted @ 2015-11-27 16:33 Weizheng_Love_Coding 阅读(88) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public int shortestDistance(String[] words, String word1, String word2) { int pre1 = -1; int pre2 = -1; ... 阅读全文
posted @ 2015-11-27 16:14 Weizheng_Love_Coding 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 这是我最开始的做法,两个指针,一个count计数,但是思路不是很清晰,代码上也有些冗余public class Solution { public int removeDuplicates(int[] nums) { int length = nums.length; ... 阅读全文
posted @ 2015-11-27 12:13 Weizheng_Love_Coding 阅读(97) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 下一页