Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 95bb85f

Browse files
Create 136-Single-Number.java
1 parent ed259ed commit 95bb85f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

java/136-Single-Number.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//We can use xor operation as it cancel out itself (i.e. only when values are different in binary representation then give output). See how xor operation works if confused.
2+
class Solution {
3+
public int singleNumber(int[] nums) {
4+
int ans = nums[0];
5+
for (int i = 1; i<nums.length; i++)
6+
ans ^= nums[i];
7+
return ans;
8+
}
9+
}

0 commit comments

Comments
 (0)