We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Beautiful Days at the Movies
Beautiful Days at the Movies
Sort by
recency
|
1773 Discussions
|
Please Login in order to post a comment
//check the code int reverse_num(int num){ int temp = 0; int neg = num < 0; if (neg) num = -num; while(num){ temp = (temp*10) + (num%10); num /= 10;
} return neg ? -temp:temp; }
int beautifulDays(int i, int j, int k) { int beautiful_count = 0;
}
My initial idea was to use str to convert to a string and reverse using indexing and convert back:
PYTHON SOLUTION
def beautifulDays(i, j, k): count = 0 for r in range(i,j+1): str1 = str(r) rev_str = str1[::-1] rev_num = int(rev_str) diff = abs(r-rev_num) num = diff/k num1 = diff//k if num == num1: count += 1 return count