public int[] singleNumbers(int[] nums) { int x = 0, y = 0, n = 0, m = 1; // Traverse XOR for(int num: nums) { n ^= num; } // Shift left in a loop, calculate m while((n & m) == 0) { m <<= 1; } // Traverse nums grouping for(int num: nums) { if((num & m) != 0) { x ^= num; } else { y ^= num; } } return new int[] {x, y}; }
Sword refers to the number of occurrences of the number in the Offer-58 array
Guess you like
Origin blog.csdn.net/a792396951/article/details/114284985
Ranking