blob: 4d6c78d92364f376864f085f8c4292ec23a4a7ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include <vector>
using std::vector;
class Solution {
public:
int maximumDifference(vector<int>& nums) {
int result = -1;
for (int i = 1; i < nums.size(); i++) {
for (int j = 0; j < i; j++) {
int diff = nums[i] - nums[j];
if (diff > result) {
result = diff;
}
}
}
return result == 0 ? -1 : result;
}
};
|