Sum of number and its reverse
October 28, 2022
math-and-geometryProblem URL: Sum of number and its reverse
We will try every number till the original given number, reverse the number and add it to the original number.
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
Time complexity: O(n)
Space complexity: O(1)