From 7d6677f0fb68658f3c9131d9c9470341346f4524 Mon Sep 17 00:00:00 2001 From: Nicole Date: Thu, 12 Jan 2017 01:15:11 -0200 Subject: [PATCH] 100% score solution --- Lesson2-OddOccurrencesInArray | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Lesson2-OddOccurrencesInArray diff --git a/Lesson2-OddOccurrencesInArray b/Lesson2-OddOccurrencesInArray new file mode 100644 index 0000000..92fb1c3 --- /dev/null +++ b/Lesson2-OddOccurrencesInArray @@ -0,0 +1,24 @@ +#include +#include +#include + +using namespace std; + +int solution(vector &A) +{ + map mapa; + for( int i = 0; i < A.size(); ++i ) + { + mapa[ A.at(i) ]++; + if(mapa[ A.at(i) ] == 2 ) + mapa.erase( A.at(i) ); + } + + return (*mapa.begin()).first; +} + +int main(int argc, char *argv[]) +{ + vector input = {42, 1000000000, 42}; + solution( input ); +} \ No newline at end of file