JAVA | EASY
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nkeep finding diff and u
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nkeep finding diff and update min element , update maxDiff only if current diff > maxDiff and also diff !=0 as num[i] < num[j]\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int maximumDifference(int[] nums) {\n        int mini = nums[0], maxDiff=-1;\n        for(int i=1;i<nums.length;i++) {\n            int diff = nums[i]-mini;\n            mini = Math.min(mini, nums[i]);\n            if(diff>maxDiff && diff !=0 ) maxDiff = diff;\n        }\n        return maxDiff;\n    }\n}\n```
['Java']