Skip to content

Commit f4a5547

Browse files
committed
Added Single Number
1 parent d98b020 commit f4a5547

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public:
3+
int singleNumber(vector<int>& nums) {
4+
int a = 0;
5+
for (int x : nums) {
6+
a ^= x;
7+
}
8+
return a;
9+
}
10+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class Solution {
2+
public int singleNumber(int[] nums) {
3+
int a = 0;
4+
for (int x : nums) {
5+
a ^= x;
6+
}
7+
return a;
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var singleNumber = function(nums) {
2+
let a = 0;
3+
for (let x of nums) {
4+
a ^= x;
5+
}
6+
return a;
7+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution(object):
2+
def singleNumber(self, nums: List[int]) -> int:
3+
a = 0
4+
5+
for x in nums:
6+
a ^= x
7+
8+
return a
9+
# Time: O(n)
10+
# Space: O(1)

0 commit comments

Comments
 (0)