public static int[] method(int[] arr) { int[] res = new int[arr.length]; Arrays.fill(res, -1); Stack<Integer> stack = new Stack<>(); for (int i = 0; i < res.length; i++) { //递减栈 while (!stack.isEmpty() && arr[stack.peek()] < arr[i]) {; res[stack.pop()]=arr[i]; } stack.push(i); } return res; }
点赞 评论

相关推荐

牛客网
牛客企业服务