You are viewing a single comment's thread. Return to all comments →
public static int beautifulDays(int i, int j, int k) { if (i < 1 || j < 1 || k < 1) return -1;
int count = 0; for (int n = i; n <= j; n++) { String wordInt = String.valueOf(n); int x = 0; int y = wordInt.length() - 1; while (x < y) { char chFront = wordInt.charAt(x); char chLast = wordInt.charAt(y); wordInt = wordInt.substring(0, x) + chLast + wordInt.substring(x + 1, y) + chFront + wordInt.substring(y + 1); x++; y--; } int num = Integer.parseInt(wordInt); int difference = Math.abs(num - n); if (difference % k == 0) { count++; } } return count; }
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Days at the Movies
You are viewing a single comment's thread. Return to all comments →
public static int beautifulDays(int i, int j, int k) { if (i < 1 || j < 1 || k < 1) return -1;