![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
LeetCode答题分享
乌龙茶不是可燃的嘛
这个作者很懒,什么都没留下…
展开
-
LeetCode153题
public static int findMin(int[] nums) { if (nums.length == 1)return nums[0]; if (nums.length == 2)return Math.min(nums[0],nums[1]); if (nums[0] < nums[nums.length-1])return nums[0]; int left = 0 ; int right = num.原创 2020-07-30 22:14:01 · 171 阅读 · 0 评论 -
LeetCode162题
public int findPeakElement(int[] nums) { if (nums.length == 0)return 0; int left = 0; int right = nums.length - 1; while (left < right){ int mid = left + (right - left)/2; if (nums[mid] < nums..原创 2020-07-30 22:10:19 · 133 阅读 · 1 评论 -
LeetCode278题
public class Solution extends VersionControl { public int firstBadVersion(int n) { int left = 0; int right = n; while(left < right){ int mid = left + (right - left)/2; if(isBadVersion(mid)){ .原创 2020-07-30 22:09:04 · 128 阅读 · 0 评论 -
LeetCode33题
public static int search(int[] nums, int target) { if(nums.length == 0)return -1; if (nums.length == 1) return nums[0] == target ? 0 : -1; int left = 0 ; int right = nums.length-1; while (left <= right){ .原创 2020-07-30 22:01:27 · 130 阅读 · 0 评论 -
LeetCode 374题
public class Solution extends GuessGame { public int guessNumber(int n) { int low = 1; int high = n; while (low <= high) { int mid = low + (high - low) / 2; int res = guess(mid); if (res ==.原创 2020-07-30 22:00:07 · 86 阅读 · 0 评论 -
LeetCode69题
public static int mySqrta(int x) { int left = 0; int right = x; int ans = -1; int mid = left + (right - left) / 2; while (left <= right) { if ((long) mid * mid <= x) { ans = mid; .原创 2020-07-30 21:57:42 · 169 阅读 · 0 评论 -
LeetCode第350题
LeetCode答题记录第350题本题使用HashMap,map记录长度较小的数组key为数,value为出现次数。遍历较长的数组与map比较,出现一次对应的value-1并记录在list集合里,如果 key不存在或者value的值为0了则不符合最后导出集合。public class Test350 { public int[] intersect(int[] nums1, int[] nums2) { if (nums1.length > nums2.length) retu原创 2020-07-13 21:22:04 · 353 阅读 · 1 评论