From 28e1ebdf0d62c52cb48317cacac3cb651e80c271 Mon Sep 17 00:00:00 2001 From: yennanliu Date: Fri, 8 Mar 2024 09:03:47 +0800 Subject: [PATCH] update 153 java, progress --- data/progress.txt | 2 +- data/to_review.txt | 18 +++++++++--------- .../FindMinimumInRotatedSortedArray.java | 19 ++++++++++++++++--- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/data/progress.txt b/data/progress.txt index 43e88195..6f32719a 100644 --- a/data/progress.txt +++ b/data/progress.txt @@ -1,4 +1,4 @@ -20240308: 152 +20240308: 152,153(again) 20240307: 139(again),141,143(again) 20240306: 121,124(again),125,128,133(again) 20240305: 100,102,104,105(again) diff --git a/data/to_review.txt b/data/to_review.txt index 1c52bfbe..dfd61103 100644 --- a/data/to_review.txt +++ b/data/to_review.txt @@ -1,4 +1,4 @@ -2024-05-02 -> ['152'] +2024-05-02 -> ['152,153(again)'] 2024-05-01 -> ['139(again),141,143(again)'] 2024-04-30 -> ['121,124(again),125,128,133(again)'] 2024-04-29 -> ['100,102,104,105(again)'] @@ -7,7 +7,7 @@ 2024-04-24 -> ['39,48(again),49,53,54'] 2024-04-23 -> ['20,21,23,33(again)'] 2024-04-22 -> ['1,3,5,4,19'] -2024-04-11 -> ['152'] +2024-04-11 -> ['152,153(again)'] 2024-04-10 -> ['139(again),141,143(again)'] 2024-04-09 -> ['121,124(again),125,128,133(again)'] 2024-04-08 -> ['100,102,104,105(again)'] @@ -16,25 +16,25 @@ 2024-04-03 -> ['39,48(again),49,53,54'] 2024-04-02 -> ['20,21,23,33(again)'] 2024-04-01 -> ['1,3,5,4,19'] -2024-03-29 -> ['152'] +2024-03-29 -> ['152,153(again)'] 2024-03-28 -> ['139(again),141,143(again)'] 2024-03-27 -> ['121,124(again),125,128,133(again)'] 2024-03-26 -> ['100,102,104,105(again)'] 2024-03-25 -> ['73,76,79(again),91,25'] 2024-03-24 -> ['55(again),56,62,70'] -2024-03-21 -> ['152', '39,48(again),49,53,54'] +2024-03-21 -> ['152,153(again)', '39,48(again),49,53,54'] 2024-03-20 -> ['139(again),141,143(again)', '20,21,23,33(again)'] 2024-03-19 -> ['121,124(again),125,128,133(again)', '1,3,5,4,19'] 2024-03-18 -> ['100,102,104,105(again)'] 2024-03-17 -> ['73,76,79(again),91,25'] -2024-03-16 -> ['152', '55(again),56,62,70'] +2024-03-16 -> ['152,153(again)', '55(again),56,62,70'] 2024-03-15 -> ['139(again),141,143(again)'] 2024-03-14 -> ['121,124(again),125,128,133(again)'] -2024-03-13 -> ['152', '100,102,104,105(again)', '39,48(again),49,53,54'] +2024-03-13 -> ['152,153(again)', '100,102,104,105(again)', '39,48(again),49,53,54'] 2024-03-12 -> ['139(again),141,143(again)', '73,76,79(again),91,25', '20,21,23,33(again)'] -2024-03-11 -> ['152', '121,124(again),125,128,133(again)', '55(again),56,62,70', '1,3,5,4,19'] -2024-03-10 -> ['152', '139(again),141,143(again)', '100,102,104,105(again)'] -2024-03-09 -> ['152', '139(again),141,143(again)', '121,124(again),125,128,133(again)', '73,76,79(again),91,25'] +2024-03-11 -> ['152,153(again)', '121,124(again),125,128,133(again)', '55(again),56,62,70', '1,3,5,4,19'] +2024-03-10 -> ['152,153(again)', '139(again),141,143(again)', '100,102,104,105(again)'] +2024-03-09 -> ['152,153(again)', '139(again),141,143(again)', '121,124(again),125,128,133(again)', '73,76,79(again),91,25'] 2024-03-08 -> ['139(again),141,143(again)', '121,124(again),125,128,133(again)', '100,102,104,105(again)', '55(again),56,62,70', '39,48(again),49,53,54'] 2024-03-07 -> ['121,124(again),125,128,133(again)', '100,102,104,105(again)', '73,76,79(again),91,25', '20,21,23,33(again)'] 2024-03-06 -> ['100,102,104,105(again)', '73,76,79(again),91,25', '55(again),56,62,70', '1,3,5,4,19'] diff --git a/leetcode_java/src/main/java/LeetCodeJava/BinarySearch/FindMinimumInRotatedSortedArray.java b/leetcode_java/src/main/java/LeetCodeJava/BinarySearch/FindMinimumInRotatedSortedArray.java index bfa835e4..55797504 100644 --- a/leetcode_java/src/main/java/LeetCodeJava/BinarySearch/FindMinimumInRotatedSortedArray.java +++ b/leetcode_java/src/main/java/LeetCodeJava/BinarySearch/FindMinimumInRotatedSortedArray.java @@ -9,15 +9,22 @@ public class FindMinimumInRotatedSortedArray { // V0 // IDEA : BINARY SEARCH (CLOSED BOUNDARY) - // NOTE !!! the turing point (rotation point) - // is ALWAYS the area that min element located (may at at i, i+1, i-1 place) + /** + * + * NOTE !!! the turing point (rotation point) + * -> is ALWAYS the area that min element located (may at at i, i+1, i-1 place) + * + * + * case 1) check turing point + * case 2) check if left / right sub array is in Ascending order + */ public int findMin(int[] nums) { if (nums.length == 0 || nums.equals(null)){ return 0; } - // already in ascending order + // check if already in ascending order if (nums[0] < nums[nums.length - 1]){ return nums[0]; } @@ -29,26 +36,32 @@ public int findMin(int[] nums) { // binary search int l = 0; int r = nums.length - 1; + /** NOTE !!! here : r >= l (closed boundary) */ while (r >= l){ int mid = (l + r) / 2; + /** NOTE !!! we found turing point, and it's the minimum element (idx = mid + 1) */ if (nums[mid] > nums[mid+1]){ return nums[mid+1]; + /** NOTE !!! we found turing point, and it's the minimum element (idx = mid -1) */ }else if (nums[mid-1] > nums[mid]){ return nums[mid]; + /** NOTE !!! compare mid with left, and this means left sub array is ascending order, * so minimum element MUST in right sub array */ }else if (nums[mid] > nums[l]){ l = mid + 1; + /** NOTE !!! compare mid with left, and this means right sub array is ascending order, * so minimum element MUST in left sub array */ }else{ r = mid - 1; } + } return nums[l];