CodeWars 쉰 세 번째 문제

Updated:

Take a Number And Sum Its Digits Raised To The Consecutive Powers And ….¡Eureka!!

public static List<Long> sumDigPow(long a, long b) {
        
    List<Long> sumDigPow = new ArrayList<Long>();

    while(a <= b) {

        if(checkSumDigPow(a)) {
            sumDigPow.add(a);
        }

        a++;
    }

    return sumDigPow;
}

private static boolean checkSumDigPow(long a) {
    long temp = a;
    long sum = 0;
    long pow = (long) (Math.log10(a) + 1);

    while(temp > 0) {
        long rest = temp % 10;
        temp = temp /10;

        sum+=(long) Math.pow(rest, pow);

        pow--;
    }

    return a == sum ? true : false;
}
  • Best 알고리즘과 똑 같았다. 사실 어려울 건 없는 문제였다.
  • 진짜 리뷰 쓸게 없다.