Skip to content

Commit e78db76

Browse files
Add 1486(C++) - Xor-operation-in-an-array (#172)
* Add xor-operation-in-an-array c++ * Add readme * Fix readme * Fix xor-operation-in-an-array
1 parent 68163cc commit e78db76

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

C++/xor-operation-in-an-array.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// difficulty easy
2+
class Solution {
3+
public:
4+
int xorOperation(int n, int start) {
5+
// brute force method
6+
int ans = 0;
7+
for(int i=0;i<n;i++){
8+
ans ^= (start + 2*i);
9+
}
10+
return ans;
11+
}
12+
};

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
8888
| 371 | [Sum of Two Integers](https://leetcode.com/problems/sum-of-two-integers/) | [Java](./Java/Sum_of_two_integers.java) | _O(1)_ | _O(1)_ | Medium |
8989
| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java) <br/> [C++](./C++/Number-Complement.cpp) | _O(1)_ | _O(1)_ | Easy | | [Tutorial](https://youtu.be/6bp5V-O3zts) |
9090
| 520 | [Detect Capital Use](https://leetcode.com/problems/detect-capital/) | [Python](./Python/detect-capital.py) <br/> [C++](./C++/Detect-Capital.cpp) | _O(n)_ | _O(1)_ | Easy | | |
91-
| 1486 | [XOR Operation in an Array](https://leetcode.com/problems/xor-operation-in-an-array/) | [Java](./Java/xor-op-in-array.java) | _O(n)_ | _O(1)_ | Easy | | Using XOR |
91+
| 1486 | [XOR Operation in an Array](https://leetcode.com/problems/xor-operation-in-an-array/) | [Java](./Java/xor-op-in-array.java) <br/> [C++](./C++/xor-operation-in-an-array.cpp) | _O(n)_ | _O(1)_ | Easy | | Using XOR |
9292

9393
<br/>
9494
<div align="right">

0 commit comments

Comments
 (0)