Skip to content

Commit ab93d30

Browse files
committedJan 2, 2019
add cpp version(do not use set)
1 parent 0741b3b commit ab93d30

File tree

1 file changed

+12
-0
lines changed
  • solution/0961.N-Repeated Element in Size 2N Array

1 file changed

+12
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
int repeatedNTimes(vector<int>& A) {
4+
unordered_set<int> us(A[0]) ;
5+
for(int i = (A.size() >> 1) - 1; i < A.size(); ++i)
6+
if(us.find(A[i]) != us.end())
7+
return A[i] ;
8+
else
9+
us.insert(A[i]) ;
10+
return A[0] ;
11+
}
12+
};

0 commit comments

Comments
 (0)
Please sign in to comment.