We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Nice solution. But you use counting sort, don't you? Also I think BitSet can save some space of array of length 10001.
public static void main( String[] args ) {
Scanner theScanner = new Scanner( System.in );
int n = theScanner.nextInt();
BitSet b = new BitSet( 10001 );
for( int i = 0 ; i < n ; i++ )
b.set( theScanner.nextInt() );
theScanner.close();
int count = 0;
int next = b.nextSetBit( 0 );
while( next > -1 ) {
count++;
next = b.nextSetBit( next + 5 );
}
System.out.print( count );
}
Priyanka and Toys
You are viewing a single comment's thread. Return to all comments →
Nice solution. But you use counting sort, don't you? Also I think BitSet can save some space of array of length 10001.