这个题只需要对数组循环一遍,记录最小值即可
class Solution {
public:
int getDis(vector<int>& A, int n) {
int minNum = A[0];
int diff = 0;
for (int i=1; i<n; i++) {
if ( A[i] <= minNum ) {
minNum = A[i];
}
diff = max(diff, A[i]-minNum);
}
return diff;
}
};