Skip to content

Commit 4f9603b

Browse files
authored
Add files via upload
1 parent 59e9a62 commit 4f9603b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

SingleNumber.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class SingleNumber {
2+
3+
public static int singleNumber(int[] nums) {
4+
//Time O(n)
5+
//Space O(1)
6+
// if we xor all duplicates are vanished and missing duplicate is found
7+
int res=0;
8+
for(int i=0;i<nums.length;i++) {
9+
res=res^nums[i];
10+
}
11+
return res^0;
12+
}
13+
14+
public static void main(String[] args) {
15+
System.out.println(singleNumber(new int[]{4,1,2,1,2}));
16+
}
17+
}

0 commit comments

Comments
 (0)