본문 바로가기

Leetcode

[Day7] Find Minimum in Rotated Sorted Array

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];
    }
}

'Leetcode' 카테고리의 다른 글

[Day6] Maximum Product Subarray  (0) 2023.02.01
[Day5] Maximum Subarray  (0) 2022.11.14
[Day3] Contains Duplicate  (0) 2022.10.26
[Day2] Best Time to Buy and Sell Stock  (0) 2022.10.25
[Day1] Two Sum  (0) 2022.10.24