这个内存使用和运行时间都击败了0.00%的人也太真实了吧 晕死.......
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param nums int一维数组
* @return int二维数组
*/
public int[][] foundMonotoneStack (int[] nums) {
// write code here
int len=nums.length;
int[][] arr=new int[len][2];
Stack<Integer> stacks=new Stack<>();
Stack<Integer> orders=new Stack<>();
int times=0;
int index=0;
while(index!=len){
if(stacks.empty()){
arr[index][0]=-1;
stacks.push(nums[index]);
orders.push(index);
index++;
}else{
if(nums[index]>stacks.peek()){
arr[index][0]=orders.peek();
stacks.push(nums[index]);
orders.push(index);
index++;
}else{
while(nums[index]<=stacks.peek()){
stacks.pop();
orders.pop();
if(stacks.empty()){
break;
}
}
}
// if(!stacks.empty()){
// arr[index][0]=orders.peek();
// stacks.push(nums[index]);
// orders.push(index);
// }
}
}
stacks.clear();
orders.clear();
index=len-1;
while(index!=-1){
if(stacks.empty()){
arr[index][1]=-1;
stacks.push(nums[index]);
orders.push(index);
index--;
}else{
if(nums[index]>stacks.peek()){
arr[index][1]=orders.peek();
stacks.push(nums[index]);
orders.push(index);
index--;
}else{
while(nums[index]<=stacks.peek()){
stacks.pop();
orders.pop();
if(stacks.empty()){
break;
}
}
}
}
}
return arr;
}
}