✅ The way you beat 🔥 100% of users 🔥
Intuition\n Describe your first thoughts on how to solve this problem. \nJust loop.\n\n# Approach\n Describe your approach to solving the problem. \n- You will 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nJust loop.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- You will use 2 points i and j to loop the array.\n- Init: i=0, j=1, ans=-1.\n- If `(nums[i] < nums[j] && nums[j] - nums[i] > ans)` then `ans = nums[j] - nums[i]`\n- Otherwise, `i=j`\n- Note. Always increase `j++` each time loop!\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n\n# Code\n```\nclass Solution {\n    public int maximumDifference(int[] nums) {\n        int n = nums.length;\n        int ans = -1;\n        int i = 0, j = 1;\n        while (i < n && j < n) {\n            if (nums[i] < nums[j]) {\n                if (nums[j] - nums[i] > ans) {\n                    ans = nums[j] - nums[i];\n                }\n            } else {\n                i = j;\n            }\n            j++;\n        }\n        return ans;\n    }\n}\n```
['Array', 'Two Pointers', 'Java']