Aracade Intro #20 arrayMaximalAdjacentDifference. Algorithm, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar
Q.
Given an array of integers, find the maximal absolute difference between any two of its adjacent elements.
주어진 정수 배열 중에서, 인접한 정수끼리 최대의 차이값(절대값) 을 구하여라
e.g.
Input -> inputArray = [2, 4, 1, 0]
Output -> arrayMaximalAdjacentDifference(inputArray) = 3.
? index 1, 2 -> 4 and 1 -> 3
//Process
//1. input parameter
//2. iterate from begin to end-1
// 2.1. check if current diff is bigger than maximalAdjacentDifference
// 2.1.1. If so -> replace mAD to current difference
//3. Return answer mAD
//처리과정
//1. 정수배열을 입력받는다.
//2. 시작부터 끝-1 까지 반복한다.
// 2.1. 한칸 앞의 값과 비교된 값이 기존 maximalAdjacentDiff 보다 큰지 확인한다
// 2.1.1. 그렇다면 -> mAD를 바꾼다
//3. 최종 mAD값을 반환한다.
Code... let me see code!!!!!!
코드... 코드를 보자!!!
int arrayMaximalAdjacentDifference(std::vector<int> inputArray) {
int mAD = 0; //maximalAdjacentDifference
for (int i = 0; i < inputArray.size() - 1; ++i)
{
if (mAD < abs(inputArray.at(i) - inputArray.at(i+1)))
{
mAD = abs(inputArray.at(i) - inputArray.at(i+1));
}
}
return mAD;
}
2018/10/08 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #12 SortByHeight
2018/10/06 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #11 IsLucky
2018/10/03 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #10 CommonCharacterCount
2018/09/26 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #9 AllLongestStrings
2018/09/24 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #8 MatrixElementsSum
2018/09/23 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #7 AlmostIncreasingSequence
2018/09/22 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #6 MakeArrayConsecutive2
2018/09/21 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #5 ShapeArea
2018/09/19 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #4 AdjacentElementsProduct
2018/09/16 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #3 CheckPalindrome
2018/09/16 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #2 CenturyFromYear
2018/09/16 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #1 Add