Skip to content

Instantly share code, notes, and snippets.

@yokolet
Created May 23, 2017 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yokolet/eb6341c79d80aa1c22d780b059b7e6e5 to your computer and use it in GitHub Desktop.
Save yokolet/eb6341c79d80aa1c22d780b059b7e6e5 to your computer and use it in GitHub Desktop.
public class LonelyInteger {
static int findLonelyInteger(int[] nums) {
int x = nums[0];
for (int i = 1; i < nums.length; i++) {
x ^= nums[i];
}
return x;
}
public static void main(String[] args) {
int[] nums = {0, 0, 1, 2, 1};
System.out.println(findLonelyInteger(nums));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment