Skip to content

Commit 874d556

Browse files
committed
update 153 java, progress
1 parent b54e18a commit 874d556

File tree

4 files changed

+133
-12
lines changed

4 files changed

+133
-12
lines changed

data/progress.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
20241124: 153
12
20241123: 253
23
20241122: 776,31
34
20241121: 004(todo),153(todo),33(todo),81(todo),34(todo),162(todo),275(todo)

data/to_review.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@
875875
2020-06-27 -> ['298', '346,686', '388', '771,775', '451,414,189', '198,203,230']
876876
2020-06-26 -> ['130', '298', '694', '155,165,167,179']
877877
2020-06-25 -> ['130', '298', '346,686', '482,127,102,107', '646', '762', '663', '725,538,089']
878-
2020-06-24 -> ['130', '346,686', '388', '776', '742', '661,662', '517,535,529', '153']
878+
2020-06-24 -> ['153', '130', '346,686', '388', '776', '742', '661,662', '517,535,529']
879879
2020-06-23 -> ['346,686', '482,127,102,107', '711,046,126,127', '131,134,150']
880880
2020-06-22 -> ['482,127,102,107', '388', '646', '771,775', '738', '701,450', '063,064,120,0146']
881881
2020-06-21 -> ['482,127,102,107', '388', '776', '396', '640,645', '675,297,138']
@@ -896,7 +896,7 @@
896896
2020-06-06 -> ['694', '663', '661,662', '701,450', '451,414,189', '836,860,863', '198,203,230']
897897
2020-06-05 -> ['269', '663', '661,662', '640,645', '155,165,167,179']
898898
2020-06-04 -> ['661,662', '701,450', '606,459', '537,553,579', '725,538,089']
899-
2020-06-03 -> ['701,450', '640,645', '517,535,529', '703,787,819', '153']
899+
2020-06-03 -> ['153', '701,450', '640,645', '517,535,529', '703,787,819']
900900
2020-06-02 -> ['269', '701,450', '640,645', '606,459', '355,119,536', '711,046,126,127', '669,682,739,763', '131,134,150']
901901
2020-06-01 -> ['640,645', '606,459', '537,553,579', '451,414,189', '063,064,120,0146', '642,652,657']
902902
2020-05-31 -> ['269', '606,459', '675,297,138', '545,617,628']
@@ -909,25 +909,25 @@
909909
2020-05-24 -> ['725,538,089', '517,535,529', '063,064,120,0146', '836,860,863', '642,652,657', '198,203,230']
910910
2020-05-23 -> ['725,538,089', '517,535,529', '711,046,126,127', '675,297,138', '545,617,628', '155,165,167,179']
911911
2020-05-22 -> ['517,535,529', '711,046,126,127', '063,064,120,0146']
912-
2020-05-21 -> ['711,046,126,127', '063,064,120,0146', '675,297,138', '836,860,863', '703,787,819', '445,508', '153']
912+
2020-05-21 -> ['153', '711,046,126,127', '063,064,120,0146', '675,297,138', '836,860,863', '703,787,819', '445,508']
913913
2020-05-20 -> ['063,064,120,0146', '675,297,138', '669,682,739,763', '322,380,394', '131,134,150']
914914
2020-05-19 -> ['675,297,138', '836,860,863', '642,652,657', '289,295']
915915
2020-05-18 -> ['836,860,863', '703,787,819', '545,617,628', '251,287']
916916
2020-05-17 -> ['836,860,863', '669,682,739,763', '231,232,240']
917917
2020-05-16 -> ['703,787,819', '642,652,657', '445,508', '198,203,230']
918918
2020-05-15 -> ['703,787,819', '669,682,739,763', '545,617,628', '322,380,394', '155,165,167,179']
919919
2020-05-14 -> ['703,787,819', '669,682,739,763', '642,652,657', '289,295']
920-
2020-05-13 -> ['669,682,739,763', '642,652,657', '545,617,628', '445,508', '251,287', '153']
920+
2020-05-13 -> ['153', '669,682,739,763', '642,652,657', '545,617,628', '445,508', '251,287']
921921
2020-05-12 -> ['642,652,657', '545,617,628', '322,380,394', '231,232,240', '131,134,150']
922922
2020-05-11 -> ['545,617,628', '445,508', '289,295', '198,203,230']
923923
2020-05-10 -> ['445,508', '322,380,394', '251,287', '155,165,167,179']
924924
2020-05-09 -> ['445,508', '322,380,394', '289,295', '231,232,240']
925-
2020-05-08 -> ['322,380,394', '289,295', '251,287', '198,203,230', '153']
925+
2020-05-08 -> ['153', '322,380,394', '289,295', '251,287', '198,203,230']
926926
2020-05-07 -> ['289,295', '251,287', '231,232,240', '155,165,167,179', '131,134,150']
927927
2020-05-06 -> ['251,287', '231,232,240', '198,203,230']
928-
2020-05-05 -> ['231,232,240', '198,203,230', '155,165,167,179', '153']
928+
2020-05-05 -> ['153', '231,232,240', '198,203,230', '155,165,167,179']
929929
2020-05-04 -> ['198,203,230', '155,165,167,179', '131,134,150']
930-
2020-05-03 -> ['155,165,167,179', '153']
930+
2020-05-03 -> ['153', '155,165,167,179']
931931
2020-05-02 -> ['153', '131,134,150']
932932
2020-05-01 -> ['153', '131,134,150']
933933
2020-04-30 -> ['131,134,150']

leetcode_java/src/main/java/LeetCodeJava/BinarySearch/FindMinimumInRotatedSortedArray.java

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,60 @@
11
package LeetCodeJava.BinarySearch;
22

3+
import java.util.Arrays;
4+
5+
36
// https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/
47

5-
import java.util.Arrays;
8+
/**
9+
* 153. Find Minimum in Rotated Sorted Array
10+
* Solved
11+
* Medium
12+
* Topics
13+
* Companies
14+
* Hint
15+
* Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:
16+
*
17+
* [4,5,6,7,0,1,2] if it was rotated 4 times.
18+
* [0,1,2,4,5,6,7] if it was rotated 7 times.
19+
* Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].
20+
*
21+
* Given the sorted rotated array nums of unique elements, return the minimum element of this array.
22+
*
23+
* You must write an algorithm that runs in O(log n) time.
24+
*
25+
*
26+
*
27+
* Example 1:
28+
*
29+
* Input: nums = [3,4,5,1,2]
30+
* Output: 1
31+
* Explanation: The original array was [1,2,3,4,5] rotated 3 times.
32+
* Example 2:
33+
*
34+
* Input: nums = [4,5,6,7,0,1,2]
35+
* Output: 0
36+
* Explanation: The original array was [0,1,2,4,5,6,7] and it was rotated 4 times.
37+
* Example 3:
38+
*
39+
* Input: nums = [11,13,15,17]
40+
* Output: 11
41+
* Explanation: The original array was [11,13,15,17] and it was rotated 4 times.
42+
*
43+
*
44+
* Constraints:
45+
*
46+
* n == nums.length
47+
* 1 <= n <= 5000
48+
* -5000 <= nums[i] <= 5000
49+
* All the integers of nums are unique.
50+
* nums is sorted and rotated between 1 and n times.
51+
*
52+
*
53+
*/
654

755
public class FindMinimumInRotatedSortedArray {
856

9-
10-
// V0
57+
// V0'
1158
// IDEA : BINARY SEARCH (CLOSED BOUNDARY)
1259
/**
1360
*
@@ -17,7 +64,7 @@ public class FindMinimumInRotatedSortedArray {
1764
* case 1) check turing point
1865
* case 2) check if left / right sub array is in Ascending order
1966
*/
20-
public int findMin(int[] nums) {
67+
public int findMin_0_1(int[] nums) {
2168

2269
if (nums.length == 0 || nums.equals(null)){
2370
return 0;
@@ -75,7 +122,7 @@ public int findMin(int[] nums) {
75122
return nums[l];
76123
}
77124

78-
// V0'
125+
// V0''
79126
// IDEA : BINARY SEARCH (OPEN BOUNDARY)
80127
public int findMin_2(int[] nums) {
81128

leetcode_java/src/main/java/dev/workspace5.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3670,6 +3670,79 @@ public int minMeetingRooms(int[][] intervals) {
36703670
return cnt;
36713671
}
36723672

3673+
// LC 153
3674+
// 5.07 PM - 5.20 PM
3675+
/**
3676+
*
3677+
* Input : [4,5,6,7,0,1,2]
3678+
*
3679+
* Case 1)
3680+
*
3681+
* right is ascending
3682+
* - the target val is bigger / smaller than cur
3683+
*
3684+
* Case 2)
3685+
*
3686+
* left is ascending
3687+
* - the target val is bigger / smaller than cur
3688+
*/
3689+
public int findMin(int[] nums) {
3690+
3691+
if (nums.length == 1){
3692+
return nums[0];
3693+
}
3694+
3695+
if (nums[0] < nums[nums.length-1]){
3696+
return nums[0];
3697+
}
3698+
3699+
// binary search
3700+
int left = 0;
3701+
int right = nums.length-1;
3702+
3703+
while (left >= right){
3704+
3705+
int mid = (left + right) / 2;
3706+
3707+
System.out.println(">>> mid = " + mid + ", left = " + left + ", right = " + right);
3708+
3709+
// turning point (???
3710+
if (nums[mid] > nums[mid+1]){
3711+
return nums[mid+1];
3712+
// turning point (????
3713+
}else if (nums[mid] < nums[mid-1]){
3714+
return nums[mid];
3715+
// norming ordering, compare mid and
3716+
}else if (nums[mid] > nums[left]){
3717+
//right = mid;
3718+
left = mid + 1;
3719+
}else{
3720+
//left = mid + 1;
3721+
right = mid-1;
3722+
}
3723+
3724+
// // right is ascending
3725+
// if (nums[mid] < nums[mid+1]){
3726+
// if (nums[mid] > nums[mid-1]){
3727+
// right = mid;
3728+
// }else{
3729+
// left = mid + 1;
3730+
// }
3731+
//
3732+
// }
3733+
// // left is ascending
3734+
// else{
3735+
// if (nums[mid] < nums[mid+1]){
3736+
// right = mid;
3737+
// }else{
3738+
// left = mid + 1;
3739+
// }
3740+
// }
3741+
}
3742+
3743+
return nums[left];
3744+
}
3745+
36733746
}
36743747

36753748

0 commit comments

Comments
 (0)