Skip to content

Commit c507cfe

Browse files
authored
Create Maximum Difference Between Increasing Elements.java
1 parent 3a07670 commit c507cfe

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int maximumDifference(int[] nums) {
3+
int currMin = nums[0];
4+
int maxDiff = -1;
5+
for (int i = 0; i < nums.length; i++) {
6+
currMin = Math.min(currMin, nums[i]);
7+
if (nums[i] != currMin) {
8+
maxDiff = Math.max(maxDiff, nums[i] - currMin);
9+
}
10+
}
11+
return maxDiff;
12+
}
13+
}

0 commit comments

Comments
 (0)