You are viewing a single comment's thread. Return to all comments →
This is my Java 8 solution, feel free to ask me any questions.
First solution:
public static int beautifulDays(int i, int j, int k) { int days = 0; while(i <= j) { //calculate reversed day String reverseDayStr = new StringBuilder(i + "") .reverse() .toString(); int reverseDay =Integer.valueOf(reverseDayStr); if( reverseDay == i || Math.abs(reverseDay - i) % k == 0) days++; i++; } return days; }
Second solution:
public static int beautifulDays(int i, int j, int k) { int days = 0; while(i <= j) { //calculate reversed day int currentDay = i; int reverseDay = 0; while(currentDay > 0) { int digit = currentDay % 10; currentDay = currentDay / 10; reverseDay = reverseDay * 10 + digit; } if( reverseDay == i || Math.abs(reverseDay - i) % k == 0) days++; i++; } return days; }
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 →
This is my Java 8 solution, feel free to ask me any questions.
First solution:
Second solution: