Best java solution
Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\n    public int maximumDifference(int[] nums) {\n        int ans
# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n    public int maximumDifference(int[] nums) {\n        int ans=-1;\n        int max = nums[nums.length-1];\n\n        for(int i=nums.length-2; i>=0; i--){\n            max = Math.max(max, nums[i]);\n            if(max <= nums[i]) continue;\n            int dif = max-nums[i];\n            ans = Math.max(ans, dif);\n            \n        }\n        return ans;\n    }\n}\n```
['Java']