fork download
  1. class Ruler
  2. {
  3. /*public static boolean f(int[] a){
  4.   int l=a.length,i=0,b=0,e=l-1;
  5.   int[] x=new int[l];
  6.   for(;i<l;i++)x[i]=i;
  7.   for(i--;i>0;i--)
  8.   if(a[i]==x[b]) b++;
  9.   else if(a[i]==x[e]) e--;
  10.   else return false;
  11.   return true;
  12.   }*/
  13. public static
  14. boolean f(int[]a){int l=a.length,i=0,b=0,e=l-1;int[]x=new int[l];for(;i<l;i++)x[i]=i;for(i--;i>0;i--)if(a[i]==x[b])b++;else if(a[i]==x[e])e--;else return 0>1;return 1>0;}
  15.  
  16. public static void main(String[] args) throws java.lang.Exception
  17. {
  18. int[] antsy={4, 3, 5, 2, 1, 0};
  19. System.out.println(f(antsy));
  20. int[] notAntsy={3, 2, 5, 4, 1, 0};
  21. System.out.println(f(notAntsy));
  22. int[] antsy2={6, 5, 4, 7, 3, 8, 9, 2, 1, 0};
  23. System.out.println(f(antsy2));
  24. int[] notAntsy2={4, 3, 5, 6, 7, 2, 9, 1, 0, 8};
  25. System.out.println(f(notAntsy2));
  26. }
  27. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
true
false
true
false