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 70cd614 commit c5df935Copy full SHA for c5df935
1 file changed
find-minimum-in-rotated-sorted-array/Yiseull.java
@@ -0,0 +1,26 @@
1
+class Solution {
2
+ public int findMin(int[] nums) {
3
+ return binarySearch(nums);
4
+ }
5
+
6
+ // 공간복잡도: O(1), 시간복잡도: O(logn)
7
+ private int binarySearch(int[] nums) {
8
+ int left = 0, right = nums.length - 1;
9
+ int answer = 5000;
10
11
+ while (left <= right) {
12
+ int mid = (left + right) / 2;
13
14
+ if (nums[right] <= nums[left] && nums[left] <= nums[mid]) {
15
+ answer = Math.min(answer, nums[mid]);
16
+ left = mid + 1;
17
18
+ else {
19
20
+ right = mid - 1;
21
22
23
24
+ return answer;
25
26
+}
0 commit comments