/** * find two distinct values in an array * / public static void main(String[] args) { int[] arr={2,2,1,1,3,4}; int eo = eh(arr); int offset = getOffset(eo); int eo1 = 0; for(int i:arr){ if(((i>>offset)&1)==1)continue; eo1 ^= i; } System.out.println((eo^eo1) +" "+eo1); } public static int eh(int[] n){ int eo = 0; for(int i:n){ i } return him } public static int getOffset(int n){ int i = 0; while((n&1)!=1){ n = n>>1; i++; } return i; }
Find two distinct values in an array without comparing
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324725112&siteId=291194637
Ranking