-
[HackerRank] Lonely Integer c++Coding Test/HackerRank 2022. 7. 20. 09:38728x90
- Problem
Given an array of integers, where all elements but one occur twice, find the unique element.
- Example
a = [1,2,3,4,3,2,1]
The unique element is 4.
- Constraints
1<=n<=100
It is guaranteed that n is an odd number and that there is one unique element.
0<=a[i] <= 100, where 0 <= i < n.
- Solutions
int lonelyinteger(vector<int> a) { unordered_map<int, int> nHash; for(auto &it : a){ nHash[it]++; } int result = 0; for(auto &it : nHash){ if(it.second == 1) result = it.first; } return result; }
728x90'Coding Test > HackerRank' 카테고리의 다른 글
[HackerRank] Zig Zag Sequence C++ (0) 2022.07.20 [HackerRank] counting sort 1 c++ (0) 2022.07.20 [HackerRank] Between Two Sets c++ (0) 2022.07.19 [HackerRank] Number Line Jumps c++ (0) 2022.07.19 [HackerRank] Apple and Orange c++ (0) 2022.07.19