Find the count of additional number needed for consecutive integer vector
입력받은 벡터에서 연속된 숫자 배열이 되기 위해 빠진 숫자의 개수를 출력한다
//Process
//1. Input statues vector<int>
//2. Get minNum and maxNum
//3. distance of min and max - length
//4. Return count
//처리과정
//1. 정수 배열 입력받는다.
//2. 정렬한다.
//3. 가장 큰수, 가장 작은수의 차이에서 정수 개수를 빼서 빠진 개수를 구한다.
//4. 결과를 출력한다.
int makeArrayConsecutive2(std::vector<int> statues) {
int count = 0;
std::sort(statues.begin(), statues.end());
count = statues[statues.size()-1] - statues[0] + 1 - statues.size();
return count;
}
2018/09/21 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #5 ShapeArea
2018/09/19 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #4 AdjacentElementsProduct
2018/09/16 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #3 CheckPalindrome
2018/09/16 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #2 CenturyFromYear
2018/09/16 - [Algorithm/Code Signal (Code Fights)] - Aracade Intro #1 Add
'Algorithm > Code Fights (Code Signal)' 카테고리의 다른 글
Aracade Intro #8 MatrixElementsSum (0) | 2018.09.24 |
---|---|
Aracade Intro #7 AlmostIncreasingSequence (0) | 2018.09.23 |
Aracade Intro #5 ShapeArea (0) | 2018.09.21 |
Aracade Intro #4 AdjacentElementsProduct (0) | 2018.09.19 |
Aracade Intro #3 CheckPalindrome (0) | 2018.09.16 |