title: Fastest algorithm to check if a number is pandigital?
body: <p>Pandigital number is a number that contains the digits 1..number length.<br>
  For example 123, 4312 and 967412385.</p>
  
  <p>I have solved many Project Euler problems, but the Pandigital problems always exceed the one minute rule.</p>
  
  <p>This is my pandigital function:  </p>
  
  <pre><code>private boolean isPandigital(int n){
      Set&lt;Character&gt; set= new TreeSet&lt;Character&gt;();   
      String string = n+"";
      for (char c:string.toCharArray()){
          if (c=='0') return false;
          set.add(c);
      }
      return set.size()==string.length();
  }
  </code></pre>
  
  <p>Create your own function and test it with this method</p>
  
  <pre><code>int pans=0;
  for (int i=123456789;i&lt;=123987654;i++){
      if (isPandigital(i)){
           pans++;
      }
  }
  </code></pre>
  
  <p>Using this loop, you should get 720 pandigital numbers. My average time was 500 millisecond.</p>
  
  <p>I'm using Java, but the question is open to any language.</p>
  
  <p><strong>UPDATE</strong><br>
  @andras answer has the best time so far, but @Sani Huttunen answer inspired me to add a new algorithm, which gets almost the same time as @andras.</p>