Skip to content

Commit 02d35fd

Browse files
Create Day 12 Single Element in a Sorted Array.cpp
1 parent ef93525 commit 02d35fd

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
PROBLEM:
2+
3+
4+
You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which
5+
appears exactly once. Find this single element that appears only once.
6+
7+
8+
9+
Example 1:
10+
11+
Input: [1,1,2,3,3,4,4,8,8]
12+
Output: 2
13+
Example 2:
14+
15+
Input: [3,3,7,7,10,11,11]
16+
Output: 10
17+
18+
19+
SOLUTION:
20+
21+
22+
class Solution {
23+
public:
24+
int singleNonDuplicate(vector<int>& nums) {
25+
26+
int ans=0;
27+
28+
for(auto k:nums)
29+
ans=ans^k;
30+
31+
return ans;
32+
}
33+
};

0 commit comments

Comments
 (0)