Question:
An int array, one side of the data without any restrictions, asking for all such numbers a[i], whose left count is less than or equal to it, the number on the right is equal to it
1 voidSmalllarge (int*arr,intN)2 {3 int*rightmin=New int[n];//record the minimum value for the right side of the original array Arr[i] (including itself)4 intLeftmax;//record Arr[i] The maximum value of the left (including yourself)5rightmin[n-1]=arr[n-1];6 for(inti=n-2; i>=0; i--)7 {8 if(rightmin[i+1]>Arr[i])9rightmin[i]=Arr[i];Ten Else Onerightmin[i]=rightmin[i+1]; A } -leftmax=arr[0]; - for(intI=0; i<n;i++) the { - if(arr[i]>=Leftmax) -leftmax=Arr[i]; - if(Leftmax==rightmin[i])//the number is the maximum number in the left-hand number and the minimum number in the right. +cout<<arr[i]<<" "; - } +}
An element in the output array that is greater than or equal to all numbers on the left and equal to the right