Leetcode: 2443. Sum of Number and Its Reverse
Understand the problem
Given an integer \(num\), return \(True\) if there is a non-negative integer \(x\) such that \(x+r(x)=num\) where \(r(x)\) is the integer generate by reverting the digits of \(x\).
Useful prompts
Devise a plan
There are only \(num\) possible numbers. Iterate over all them and return \(True\) if one satisfy the condition.
Carry out the plan
class Solution: def sumOfNumberAndReverse(self, num: int) -> bool: for i in range(num + 1): if i + int(str(i)[::-1]) == num: return True return False