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 static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. int nums[]={1,1,2,3,3,4,4};
  14. int l=0;
  15. int r=nums.length-1;
  16. while(l<r){
  17. int mid=(l+r)/2;
  18. if(mid%2==0){
  19. if(nums[mid]==nums[mid+1]){
  20. l=mid+2;
  21. }
  22. else{
  23. r=mid;
  24. }
  25. }
  26. else{
  27. if(nums[mid]==nums[mid-1]){
  28. l=mid+1;
  29. }
  30. else{
  31. r=mid;
  32. }
  33. }
  34. }
  35. System.out.println(nums[l]);
  36. }
  37. }
  38.  
Success #stdin #stdout 0.08s 16528KB
stdin
Standard input is empty
stdout
2