728. Self Dividing Numbers

728. Self Dividing Numbers

class Solution {
	public static boolean isSelfDividing( int i){
		for ( int x = i ; x > 0 ; x /=10){
			int m = x % 10;
			if( m == 0 /*to avoid i%0*/|| i % m != 0) return false;
		}
		return true;
	}
    public List selfDividingNumbers(int left, int right) {
    	List out = new ArrayList();
    	
    	for ( int i = left ; i <= right ; i++ ){
    		if ( isSelfDividing(i)) out.add(i);
    	}
    	return out;
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s