Leetcode
[Day7] Find Minimum in Rotated Sorted Array
hsooooo
2023. 2. 1. 21:38
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/
Find Minimum in Rotated Sorted Array - LeetCode
Find Minimum in Rotated Sorted Array - Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become: * [4,5,6,7,0,1,2] if it was rotated 4 times. * [0,1,2,4,5,6,7] if it
leetcode.com
<문제 설명>
회전 배열에서 가장 작은 요소를 리턴해라. 시간 복잡도는 O(log n).
<풀이 과정>
정렬문제라고 생각. Java의 sort()를 사용했다. 이분탐색을 직접 구현해봐야겠다.
<풀이 코드>
class Solution {
public int findMin(int[] nums) {
Arrays.sort(nums);
return nums[0];
}
}