Skip to content

Commit 4f87fdb

Browse files
committed
find minimum in rotated sorted array
1 parent a1645c8 commit 4f87fdb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var findMin = function(nums) {
6+
// nums는 rotated 된 array
7+
// return 값은 이 nums에서 최솟값을 return 해야함.
8+
const NUMS_LENGTH = nums.length;
9+
10+
let result = nums[0];
11+
12+
for(let i = 0; i < NUMS_LENGTH; i++ ){
13+
let currentIndex = NUMS_LENGTH - i;
14+
15+
if(nums[currentIndex - 1] > nums[currentIndex]){
16+
result = nums[currentIndex];
17+
}else{
18+
continue;
19+
}
20+
}
21+
return result;
22+
};

0 commit comments

Comments
 (0)