Maximum Difference Between Increasing Elements LeetCode solution in Java
1class Solution {2public int maximumDifference(int[] nums) {3if (nums.length < 2) return -1;4int result = Integer.MIN_VALUE;5int minValue = nums[0];6for (int i = 1; i < nums.length; i++) {7if (nums[i] > minValue) result = Math.max(result, nums[i] - minValue);8minValue = Math.min(minValue, nums[i]);9}10return result == Integer.MIN_VALUE ? -1 : result;11}12}