import java.util.*;
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int一维数组 * @return int二维数组 */ public int[][] foundMonotoneStack (int[] nums) { int len = nums.length; int[][] matrix = new int[len][2]; matrix[0][0] = -1; matrix[len -1][1] = -1; for(int i = 1;i <len;i++){ int temp = i - 1; while(temp != -1 && nums[i] <= nums[temp]){ temp = matrix[temp][0]; } matrix[i][0] = temp; } for(int i = len - 2;i >= 0;i--){ int temp = i + 1; while(temp != -1 && nums[i] <= nums[temp]){ temp = matrix[temp][1]; } matrix[i][1] = temp; } return matrix; } }