Find local minima in an array

后端 未结 7 1596
时光说笑
时光说笑 2020-12-04 09:56

Given an array of integers, find the local minima. An element A[i] is defined as a local minimum if A[i-1] > A[i] and A[i] < A[i+1] where i = 1...n-2. In case of boundar

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 10:42

    The original question is not complete.

    Just found the complete question and full-detailed explanation at Find local minima in an array! - not my blog

    Given an array of unique integers whose first two numbers are decreasing and last two numbers are increasing, find a number in the array which is local minima. A number in the array is called local minima if it is smaller than both its left and right numbers.

    For example in the array 9,7,2,8,5,6,3,4 2 is a local minima as it is smaller than its left and right number 7 and 8. Similarly 5 is another local minima as it is between 8 and 6, both larger than 5.

    You need to find any one of the local minima.

提交回复
热议问题