Maximum Difference Between Increasing Elements LeetCode solution in Java

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

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0