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 78bec4d commit 315365dCopy full SHA for 315365d
find-minimum-in-rotated-sorted-array/TonyKim9401.java
@@ -0,0 +1,25 @@
1
+// TC: O(log n)
2
+// Using binary search, it takes `log n` time complexity, n indicates the length of the given array nums
3
+// SC: O(1)
4
+// constant space occupation
5
+class Solution {
6
+ public int findMin(int[] nums) {
7
+
8
+ int start = 0;
9
+ int end = nums.length - 1;
10
+ int min = Integer.MAX_VALUE;
11
12
+ while (start <= end) {
13
+ int mid = start + (end - start) / 2;
14
15
+ if (nums[start] <= nums[mid]) {
16
+ min = Math.min(min, nums[start]);
17
+ start = mid + 1;
18
+ } else if (nums[mid] <= nums[end]) {
19
+ min = Math.min(min, nums[mid]);
20
+ end = mid - 1;
21
+ }
22
23
+ return min;
24
25
+}
0 commit comments