Skip to content

Commit ef5b1fa

Browse files
authored
Create n-repeated-element-in-size-2n-array.cpp
1 parent f6ca055 commit ef5b1fa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int repeatedNTimes(vector<int>& A) {
7+
for (int i = 2; i < A.size(); ++i) {
8+
if (A[i - 1] == A[i] || A[i - 2] == A[i]) {
9+
return A[i];
10+
}
11+
}
12+
return A[0];
13+
}
14+
};

0 commit comments

Comments
 (0)