Created
May 23, 2017 13:22
-
-
Save yokolet/eb6341c79d80aa1c22d780b059b7e6e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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