Skip to content

Commit

Permalink
Merge pull request #53 from Rahul-Bhati/master
Browse files Browse the repository at this point in the history
solution of #39 issue
  • Loading branch information
Rohit0301 authored Oct 2, 2022
2 parents c830ede + b1fc47b commit 8c8f406
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Leetcode/single-number-iii#39.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Solution {
public int[] singleNumber(int[] nums) {
int res = 0;
for(int i=0;i<nums.length;i++)
res = res ^ nums[i] ;

res = (res & -res) ;
int a=0;
int b=0;
for(int i=0;i<nums.length;i++) {
if((nums[i] & res) > 0)
a = (a^nums[i]) ;
else
b = (b^nums[i]) ;
}

int[] ar = new int[2];

if(a<=b){
ar[0]=a;
ar[1]=b;
}else{
ar[0]=b;
ar[1]=a;
}

return ar;
}
}

0 comments on commit 8c8f406

Please sign in to comment.