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 65cefcc commit 867f27fCopy full SHA for 867f27f
โfind-minimum-in-rotated-sorted-array/YeomChaeeun.ts
@@ -22,18 +22,16 @@ function findMin(nums: number[]): number {
22
23
// ์ด๋ถ ํ์๋ฒ ํ์ฉ
24
// ์ ๋ฐ์ฉ ์๋ผ์ nums[n-1] > nums[n] ์ ์ง์ ์ ์ฐพ๋๋ค
25
- let low = 1;
+ let low = 0;
26
let high = nums.length - 1;
27
- while(low <= high) {
28
- let mid = Math.floor((low + high) / 2);
29
- if(nums[mid - 1] > nums[mid]) {
30
- return nums[mid];
31
- }
32
- if(nums[0] < nums[mid]) {
+ while(low < high) {
+ let mid = low + Math.floor((high - low) / 2);
+
+ if(nums[mid] > nums[high]) {
33
low = mid + 1;
34
} else {
35
- high = mid -1;
+ high = mid;
36
}
37
38
- return nums[0]
+ return nums[low]
39
0 commit comments