File tree 5 files changed +57
-0
lines changed
algorithms/FindMinimumInRotatedSortedArray
5 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -291,6 +291,7 @@ All solutions will be accepted!
291
291
| 890| [ Find And Replace Pattern] ( https://leetcode-cn.com/problems/find-and-replace-pattern/description/ ) | [ java/py/js] ( ./algorithms/FindAndReplacePattern ) | Medium|
292
292
| 48| [ Rotate Image] ( https://leetcode-cn.com/problems/rotate-image/description/ ) | [ java/py/js] ( ./algorithms/RotateImage ) | Medium|
293
293
| 74| [ Search A 2d Matrix] ( https://leetcode-cn.com/problems/search-a-2d-matrix/description/ ) | [ java/py/js] ( ./algorithms/SearchA2dMatrix ) | Medium|
294
+ | 153| [ Find Minimum In Rotated Sorted Array] ( https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/description/ ) | [ java/py/js] ( ./algorithms/FindMinimumInRotatedSortedArray ) | Medium|
294
295
295
296
# Database
296
297
| #| Title| Solution| Difficulty|
Original file line number Diff line number Diff line change
1
+ # Find Minimum In Rotated Sorted Array
2
+ We can solve this problem by binary search
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public int findMin (int [] nums ) {
3
+ int low = 0 ,
4
+ high = nums .length - 1 ;
5
+
6
+ while (low < high - 1 ) {
7
+ int mid = (low + high ) / 2 ;
8
+
9
+ if (nums [mid ] < nums [high ])
10
+ high = mid ;
11
+ else if (nums [mid ] > nums [high ])
12
+ low = mid ;
13
+ }
14
+
15
+ return Math .min (nums [low ], nums [high ]);
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } nums
3
+ * @return {number }
4
+ */
5
+ var findMin = function ( nums ) {
6
+ let low = 0 ,
7
+ high = nums . length - 1
8
+
9
+ while ( low < high - 1 ) {
10
+ let mid = parseInt ( ( low + high ) / 2 )
11
+
12
+ if ( nums [ mid ] < nums [ high ] )
13
+ high = mid
14
+ else if ( nums [ mid ] > nums [ high ] )
15
+ low = mid
16
+ }
17
+
18
+ return Math . min ( nums [ low ] , nums [ high ] )
19
+ } ;
Original file line number Diff line number Diff line change
1
+ class Solution (object ):
2
+ def findMin (self , nums ):
3
+ """
4
+ :type nums: List[int]
5
+ :rtype: int
6
+ """
7
+ low = 0
8
+ high = len (nums ) - 1
9
+
10
+ while low < high - 1 :
11
+ mid = (low + high ) / 2
12
+
13
+ if nums [mid ] < nums [high ]:
14
+ high = mid
15
+ elif nums [mid ] > nums [high ]:
16
+ low = mid
17
+
18
+ return min (nums [low ], nums [high ])
You can’t perform that action at this time.
0 commit comments