Skip to content

Commit

Permalink
update 153 java, progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Mar 8, 2024
1 parent 895de9f commit 28e1ebd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion data/progress.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
18 changes: 9 additions & 9 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -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)']
Expand All @@ -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)']
Expand All @@ -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']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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];
Expand Down

0 comments on commit 28e1ebd

Please sign in to comment.