class Solution { public int[] nextGreaterElements(int[] nums) { int[] res = new int[nums.length]; Arrays.fill(res, -1); Stack<Integer> stack = new Stack<>(); // 存储的是索引index // 由于是循环数组,对于末位元素,要往后循环考虑到其前一位数也就是倒数第二个数 for(int i =...