-
[codility] OddOccurrencesInArray c++Coding Test/codility 2022. 4. 8. 16:02728x90
- 문제
- 문제 풀이
#include <string> #include <vector> #include <algorithm> int solution(std::vector<int> &A) { // write your code in C++14 (g++ 6.2.0) sort(A.begin(), A.end()); for (int i = 0; i < A.size(); i += 2) { if (A[i] != A[i + 1]) { return A[i]; } } return 0; } #define OddOccurrencesInArray #ifdef OddOccurrencesInArray int main() { std::vector<int> A = {9,3,9,3,9,7,9}; std::cout << solution(A); return 0; } #endif
728x90'Coding Test > codility' 카테고리의 다른 글
[codility] TapeEquilibrium c++ (0) 2022.04.09 [codility] PermMissingElem c++ (0) 2022.04.09 [codility] FrogJmp c++ (0) 2022.04.08 [codility] CyclicRotation c++ (0) 2022.04.08 [codility] BinaryGap c++ (0) 2022.04.08