알고리즘/codefights
20>arrayMaximalAdjacentDifference
Diademata
2017. 7. 4. 13:52
반응형
Given an array of integers, find the maximal absolute difference between any two of its adjacent elements. Example For inputArray = [2, 4, 1, 0], the output should be arrayMaximalAdjacentDifference(inputArray) = 3. |
code >>
int arrayMaximalAdjacentDifference(std::vector<int> inputArray) {
int max = -987654321;
for (int i = 0; i<inputArray.size() - 1 ; i++)
{
max = std::max(max, std::abs(inputArray[i] - inputArray[i + 1]));
}
return max;
}
반응형