We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3e99718 commit 3e7983cCopy full SHA for 3e7983c
find-minimum-in-rotated-sorted-array/yolophg.js
@@ -0,0 +1,24 @@
1
+// Time Complexity: O(n log n)
2
+// Space Complexity: O(1)
3
+
4
+var findMin = function(nums) {
5
+ // initialize left pointer.
6
+ let left = 0;
7
+ // initialize right pointer.
8
+ let right = nums.length - 1;
9
10
+ while (left < right) {
11
+ // calculate the middle index.
12
+ let mid = left + ((right - left) / 2 | 0);
13
14
+ // if the value at the middle index is bigger, move the left pointer to the right.
15
+ if (nums[mid] > nums[right]) {
16
+ left = mid + 1;
17
+ } else { // else, move the right pointer to the middle index.
18
+ right = mid;
19
+ }
20
21
22
+ // return the element which is the minimum pointed to by the left pointer.
23
+ return nums[left];
24
+};
0 commit comments