1. The subject

  • 11. Rotate the smallest number in the array
  • Difficulty: Easy

2. Describe

Moving the beginning elements of an array to the end of the array is called array rotation. Take a rotation of an incrementally sorted array and print the smallest element of the rotation array. For example, the array [3,4,5,1,2] is a rotation of [1,2,3,4,5], whose minimum value is 1.

Example 1:

Input:,4,5,1,2 [3]

Output: 1.

Example 2:

Input:,2,2,0,1 [2]

Output: 0

3. Implementation method

3.1 method 1

3.1.1 ideas

The first reaction is to just sort the array and return the minimum, which doesn’t matter whether it’s rotated or not, so here’s the implementation;

3.1.2 implementation

public int minArray(int[] numbers) {
    // Output the minimum value after sorting.
    Arrays.sort(numbers);
    return numbers[0];
}
Copy the code

This article is participating in the “Nuggets 2021 Spring Recruitment Campaign”, click to see the details of the campaign