From 4cb2e2f971cf49ef9ffb82a4777cd86c89e9e802 Mon Sep 17 00:00:00 2001 From: CyC2018 <1029579233@qq.com> Date: Mon, 11 Jun 2018 09:33:00 +0800 Subject: [PATCH] auto commit --- notes/Leetcode 题解.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/notes/Leetcode 题解.md b/notes/Leetcode 题解.md index f9c51502..1e6c9b76 100644 --- a/notes/Leetcode 题解.md +++ b/notes/Leetcode 题解.md @@ -994,10 +994,11 @@ public int firstBadVersion(int n) { int l = 1, h = n; while (l < h) { int mid = l + (h - l) / 2; - if (isBadVersion(mid)) + if (isBadVersion(mid)) { h = mid; - else + } else { l = mid + 1; + } } return l; } @@ -1017,10 +1018,11 @@ public int findMin(int[] nums) { int l = 0, h = nums.length - 1; while (l < h) { int m = l + (h - l) / 2; - if (nums[m] <= nums[h]) + if (nums[m] <= nums[h]) { h = m; - else + } else { l = m + 1; + } } return nums[l]; } @@ -1042,20 +1044,22 @@ Output: [-1,-1] public int[] searchRange(int[] nums, int target) { int first = binarySearch(nums, target); int last = binarySearch(nums, target + 1) - 1; - if (first == nums.length || nums[first] != target) + if (first == nums.length || nums[first] != target) { return new int[]{-1, -1}; - else + } else { return new int[]{first, Math.max(first, last)}; + } } private int binarySearch(int[] nums, int target) { int l = 0, h = nums.length; // 注意 h 的初始值 while (l < h) { int m = l + (h - l) / 2; - if (nums[m] >= target) + if (nums[m] >= target) { h = m; - else + } else { l = m + 1; + } } return l; }