Easy java approach
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nAssume there are two array one by one.\n Describe your approach to solvin
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nAssume there are two array one by one.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n- $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n- $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[] nextGreaterElements(int[] nums) {\n        int n = nums.length;\n        Stack<Integer> s = new Stack<>();\n        int[] arr = new int[n];\n        for(int i = 2 * n - 1; i >= 0 ; i--){\n            while(!s.isEmpty() && s.peek() <= nums[i % n]){\n                s.pop();\n            }\n            if(s.isEmpty()){\n                arr[i % n] = -1;\n            }\n            else{\n                arr[i % n] = s.peek();\n            }\n            s.push(nums[i % n]);\n        }\n        return arr;\n    }\n}\n```
['Java']