Title:
If the continuous subarray B of an integer array A satisfies the following properties, then we compose the subarray into "peaks"
len(B)>=3
There is a variable i, 0 < I < len (B) - 1, B [0] <... B[i]>... B[len(B)-1]
B may be the complete works of A.
Now give me an array A to find the longest peak length.
Output 0 if there are no peaks

Input:
N Array Size
 N digits denote array elements

Output:
Longest Peak Length

Method: Dynamic programming
Train of thought:
One-dimensional dynamic programming converted into two parts
(1) Continuous rise on the left: if the number on the right is greater than the number on the left, then the left is right = left + 1;
(2) Continuous decline on the right: if the number on the left is greater than the number on the right, then right is left = right + 1;
If not, each place is initialized to 1
Then define max to traverse the array and find the largest subscript of right+left
Finally, because the peak was calculated twice, subtract one.
If the final max is not >= 3 & & the left and right of this point are not at the same time >= 2, the peak cannot be formed.

Code:

 public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i <n ; i++) {
            nums[i]=sc.nextInt();
        }
        System.out.println(mount(nums));
    }
    public static int mount(int[] array) {
        int[] left = new int[array.length];//Ascending subsequence
        int[] right = new int[array.length];//Ascending subsequence
        //Ascending subsequence
        left[0]=1;
        for (int i = 1; i <array.length ; i++) {
            if(array[i]>array[i-1]){
                left[i]=left[i-1]+1;
            }else{
                left[i]=1;
            }
        }
        //Descending subsequence
        right[array.length-1]=1;
        for (int i = array.length-2; i>=0 ; i--) {
            if(array[i]>array[i+1]){
                right[i]=right[i+1]+1;
            }else{
                right[i]=1;
            }
        }
        int max=0,j;
        for (int i = 0; i <array.length ; i++) {
            if(max<left[i]+right[i]){
                max=left[i]+right[i];
                j=i;
            }
        }
        if(max>=4&&right[j]>=2&&left[j]>=2){
            return max-1;
        }
        return 0;
    }