LoginSignup
0
0

More than 1 year has passed since last update.

Leetcode 153. Find Minimum in Rotated Sorted Array

Last updated at Posted at 2022-11-18

153. Find Minimum in Rotated Sorted Array

アプローチ

1. 二分探索

class Solution {
    public int findMin(int[] nums) {
        int start = 0;
        int end = nums.length - 1;

        while(start < end){
            int mid = start + (end - start) / 2;
            if(nums[mid] > nums[end]){
                start = mid + 1;
            }else{
                end = mid;
            }
        }
        return nums[start];
    }
}

2. ソート

class Solution {
    public int findMin(int[] nums) {
        Arrays.sort(nums);
        return nums[0];
    }
}
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0