Ad
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;
      }
    }
    • import java.util.*;
    • class Solution {
    • public static int retSmallestPositiveInteger() {
    • for(int i=1; ; i++) {
    • if(hasSameDigits(i, i*2) && hasSameDigits(i, i*3) && hasSameDigits(i, i*4) && hasSameDigits(i, i*5) && hasSameDigits(i, i*6))
    • return i;
    • }
    • }
    • 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 hasSameDigits(int x, int y) {
    • char[] xdigits = Integer.toString(x).toCharArray();
    • char[] ydigits = Integer.toString(y).toCharArray();
    • Arrays.sort(xdigits);
    • Arrays.sort(ydigits);
    • return Arrays.equals(xdigits, ydigits);
    • }
    • 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;
    • }
    • }