[JAVA] Easy to understand java solution.
Complexity\n- Time complexity O(n)\n\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\n    public int maximumDifference(int[] nums) {\n        int res=0;
# Complexity\n- Time complexity $$O(n)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution {\n    public int maximumDifference(int[] nums) {\n        int res=0;\n        int min=nums[0];\n        for(int i=1; i<nums.length; i++){\n            res=Math.max(res, nums[i]-min);\n            min=Math.min(min, nums[i]);\n        }\n        if(res==0) return -1;\n        return res;\n    }\n}\n```
['Array', 'Java']