반응형
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A) {
// write your code in C++14 (g++ 6.2.0)
vector<int> v;
int count = 1, cmp = 0;
for(int i = 1; i < A.size() - 1; i++){
if(A[i - 1] < A[i] && A[i] > A[i + 1])
v.emplace_back(i);
}
if(v.size() < 2) return v.size();
if(A[A.size() - 1] > A[A.size() - 2]){
v.pop_back();
v.emplace_back(A.size() - 1);
}
int flag = 2;
while(true){
int num = v[0];
for(int i = 1; i < v.size(); i++){
if(v[i] - num > flag){
count++;
num = v[i];
if(flag == count){
cmp = count;
count = 1;
break;
}
}
}
if(flag > cmp)
return cmp;
flag++;
}
}
https://app.codility.com/demo/results/trainingWAZP37-GEU/
한틱 차이로 53점..... 지금은 해결방법이 생각 안나니 나중에 다시 풀어보자...!!
반응형
'코딩테스트 > Codility' 카테고리의 다른 글
[C++ 풀이] Codility - Lessons 9 (Maximum slice problem), MaxDoubleSliceSum (0) | 2019.12.10 |
---|---|
[C++ 풀이] Codility - Lessons 9 (Maximum slice problem), MaxSliceSum (0) | 2019.11.08 |
[C++ 풀이] Codility - Lessons 9 (Maximum slice problem), MaxProfit (0) | 2019.11.04 |
[C++ 풀이] Codility - Lessons 8 (Leader), EquiLeader (0) | 2019.10.07 |
[C++ 풀이] Codility - Lessons 8 (Leader), Dominator (0) | 2019.10.04 |
댓글