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 5f4f2e5 commit 7fe3df4Copy full SHA for 7fe3df4
โfind-minimum-in-rotated-sorted-array/se6816.javaโ
@@ -13,3 +13,30 @@ public int findMin(int[] nums) {
13
return result;
14
}
15
16
+
17
+/**
18
+ ์ด๋ถ ํ์์ ํตํด, ์ต์ ์์๋ฅผ ๊ตฌํ๋ ๋ฐฉ์
19
+ nums์ ๊ธธ์ด -> N
20
+ ์๊ฐ ๋ณต์ก๋ : O(logN)
21
+ ๊ณต๊ฐ ๋ณต์ก๋ : O(1)
22
+*/
23
+class Solution {
24
+ public int findMin(int[] nums) {
25
+ return nums[binarySearch(nums)];
26
+ }
27
28
+ public int binarySearch(int[] nums) {
29
+ int start = 0;
30
+ int end = nums.length -1;
31
+ while(start < end) {
32
+ int mid = (start + end) / 2;
33
+ if(nums[mid] < nums[end]) {
34
+ end = mid;
35
+ } else {
36
+ start = mid + 1;
37
38
39
+ return start;
40
41
+}
42
0 commit comments