2144. Maximum Difference Between Increasing Elements
My accepted C++ solution to LeetCode problem 2144, Maximum Difference Between Increasing Elements, running in 0ms.
- Difficulty: Easy
- C++
- Runtime 0ms
- Memory 11.9MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 11.9MB, accepted 2025-12-27.
class Solution {
public:
int maximumDifference(vector<int>& nums) {
int minVal = nums[0], maxDiff = -1;
for (int i = 1; i < nums.size(); i++) {
if (nums[i] > minVal) maxDiff = max(maxDiff, nums[i] - minVal);
minVal = min(minVal, nums[i]);
}
return maxDiff;
}
};