fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public int singleNumber(int[] nums) {
  11. int sing = nums[0];
  12. for (int i = 1; i < nums.length; i++) {
  13. sing = sing ^ nums[i];
  14. }
  15. return sing;
  16.  
  17. }
  18.  
  19. public static void main (String[] args) throws java.lang.Exception
  20. {
  21. // your code goes here
  22. Ideone x = new Ideone();
  23. int[] arr = {4, 5, 5, 2, 2};
  24. System.out.println(x.singleNumber(arr));
  25. }
  26. }
Success #stdin #stdout 0.06s 32288KB
stdin
Standard input is empty
stdout
4