You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: binary-search/BinarySearch.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -804,11 +804,11 @@ class RotationCountOfRotatedArray {
804
804
int mid = start + (end - start) /2;
805
805
if (mid < end
806
806
&& arr[mid] > arr[mid
807
-
+1]) // if mid is greater than the next element[^1^][1]
807
+
+1]) // if mid is greater than the next element
808
808
return mid +1;
809
809
if (mid > start
810
810
&& arr[mid -1] > arr[mid]) // if mid is smaller than the
811
-
// previous element[^1^][1]
811
+
// previous element
812
812
return mid;
813
813
814
814
if (arr[start] < arr[mid]) { // left side is sorted, so the pivot is
@@ -852,11 +852,11 @@ class RotationCountWithDuplicates {
852
852
int mid = start + (end - start) /2;
853
853
if (mid < end
854
854
&& arr[mid] > arr[mid +1]) // if element at mid is greater than
855
-
// the next element[^1^][1]
855
+
// the next element
856
856
return mid +1;
857
857
if (mid > start
858
858
&& arr[mid -1] > arr[mid]) // if element at mid is smaller than
859
-
// the previous element[^1^][1]
859
+
// the previous element
860
860
return mid;
861
861
862
862
// this is the only difference from the previous solution
@@ -865,11 +865,11 @@ class RotationCountWithDuplicates {
865
865
// ends if they are not the smallest number
866
866
if (arr[start] == arr[mid] && arr[end] == arr[mid]) {
867
867
if (arr[start] > arr[start +1]) // if element at start+1 is not
868
-
// the smallest[^1^][1]
868
+
// the smallest
869
869
return start +1;
870
870
++start;
871
871
if (arr[end -1] > arr[end]) // if the element at end is not the
872
-
// smallest[^1^][1]
872
+
// smallest
873
873
return end;
874
874
--end;
875
875
// left side is sorted, so the pivot is on right side
@@ -1324,4 +1324,4 @@ class Solution {
1324
1324
**Complexity:**
1325
1325
- Time: O(n log m), O(n log m), where n is the number of weights and m is the total weight. This is because we perform a binary search over the ship capacities, and for each capacity, we check if it’s possible to ship all weights within the given days in O(n) time.
0 commit comments