package main
import"fmt"funcminArray(numbers []int)int{iflen(numbers)==0{return-1}
n :=len(numbers)-1for; n >0&& numbers[0]== numbers[n];{
n--}if numbers[0]<= numbers[n]{return numbers[0]}
l :=0
r := n
for; l < r;{
mid :=(l + r)>>1if numbers[mid]< numbers[0]{
r = mid
}else{
l = mid +1}}return numbers[r]}funcmain(){
numbers :=[]int{2,2,2,0,1}
fmt.Println(minArray(numbers))}
Python
from typing import List
classSolution:defminArray(self, numbers: List[int])->int:ifnot numbers:return-1
n =len(numbers)-1while n and numbers[0]== numbers[n]: n -=1if numbers[0]<= numbers[n]:return numbers[0]
l =0
r = n
while l < r:
mid = l + r >>1if numbers[mid]< numbers[0]:
r = mid
else:
l = mid +1return numbers[r]if __name__ =="__main__":
numbers =[3,4,5,1,2]
solution = Solution()print(solution.minArray(numbers))
C#
publicclassSolution{publicintMinArray(int[] numbers){if(numbers.Length ==0)return-1;int n = numbers.Length -1;while(n !=0&& numbers[0]== numbers[n]){
n--;}if(numbers[0]<= numbers[n])return numbers[0];int l =0;int r = n;while(l < r){int mid =(l + r)>>1;if(numbers[mid]< numbers[0]){
r = mid;}else{
l = mid +1;}}return numbers[r];}}classProgram{staticvoidMain(string[] args){int[] numbers ={3,4,5,1,2};Solution solution =newSolution();
Console.WriteLine(solution.MinArray(numbers));}}