Code
Diff
  • import java.util.*;
    class Solution {
      
      public static int retSmallestPositiveInteger() {
        int number = 9; // for sure doesnt exists before 10 XD
        boolean smallest = false;
        do {
          smallest = isSmallestPositiveInteget(++number, 2);
        }
        while (!smallest);
        return number;
      }
      
      private static boolean isSmallestPositiveInteget(int i, int factor) {
        if (factor > 6) {
          return true;
        }
        if (hasSameDigits(i, i*factor)) {
          return isSmallestPositiveInteget(i, ++factor);
        }
        return false;
      }
    
    	private static boolean hasSameDigits(int x, int y) {
    	  char[] xdigits = Integer.toString(x).toCharArray();
    		char[] ydigits = Integer.toString(y).toCharArray();
        Arrays.sort(xdigits);
        Arrays.sort(ydigits);
    		int hashX = Arrays.hashCode(xdigits);
    		int hashY = Arrays.hashCode(ydigits);
    		return hashX == hashY;
      }
    }
  • 11
    import java.util.*;
    
    22
    class Solution {
    
    33
      
    
    4
    	   
    
    5
         public static int retSmallestPositiveInteger() {
    
    6
             for(int i=1; ; i++) {
    
    7
                if(hasSameDigits(i, i*2) && hasSameDigits(i, i*3) && hasSameDigits(i, i*4) && hasSameDigits(i, i*5) && hasSameDigits(i, i*6))
    
    8
                   return i; 
    
    9
             }
    
    10
         }
    
    4+
      public static int retSmallestPositiveInteger() {
    
    5+
        int number = 9; // for sure doesnt exists before 10 XD
    
    6+
        boolean smallest = false;
    
    7+
        do {
    
    8+
          smallest = isSmallestPositiveInteget(++number, 2);
    
    9+
        }
    
    10+
        while (!smallest);
    
    11+
        return number;
    
    12+
      }
    
    1111
      
    
    12
    	    private static boolean hasSameDigits(int x, int y) {
    
    13
    		      char[] xdigits = Integer.toString(x).toCharArray();
    
    14
    		      char[] ydigits = Integer.toString(y).toCharArray();
    
    15
    		      Arrays.sort(xdigits);
    
    16
    		      Arrays.sort(ydigits);
    
    17
    		      return Arrays.equals(xdigits, ydigits);
    
    18
          }
    
    14+
      private static boolean isSmallestPositiveInteget(int i, int factor) {
    
    15+
        if (factor > 6) {
    
    16+
          return true;
    
    17+
        }
    
    18+
        if (hasSameDigits(i, i*factor)) {
    
    19+
          return isSmallestPositiveInteget(i, ++factor);
    
    20+
        }
    
    21+
        return false;
    
    22+
      }
    
    23+
    24+
    	private static boolean hasSameDigits(int x, int y) {
    
    25+
    	  char[] xdigits = Integer.toString(x).toCharArray();
    
    26+
    		char[] ydigits = Integer.toString(y).toCharArray();
    
    27+
        Arrays.sort(xdigits);
    
    28+
        Arrays.sort(ydigits);
    
    29+
    		int hashX = Arrays.hashCode(xdigits);
    
    30+
    		int hashY = Arrays.hashCode(ydigits);
    
    31+
    		return hashX == hashY;
    
    32+
      }
    
    1919
    }