Sherlock and The Beast

  • + 0 comments

    Java 8

        static String aDecentNumber(int n) {
            int temp = n;
            while (temp >= 3) {
                if (temp % 3 == 0) {
                    return fillNo(5, temp) + fillNo(3, n - temp);
                }
                temp -= 5;
                if (temp == 0) {
                    return fillNo(3, n);
                }
            }
            return "-1";
        }
    
        static String fillNo(int no, int times) {
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < times; i++) {
                sb.append(no);
            }
            return sb.toString();
        }