Talentd
FleetCode

2443. Sum of Number and Its Reverse

Medium50.0% acceptance1 company

Given a non-negative integer num, return true if num can be expressed as the sum of any non-negative integer and its reverse, or false otherwise.

Example 1:

Input: num = 443
Output: true
Explanation: 172 + 271 = 443 so we return true.

Example 2:

Input: num = 63
Output: false
Explanation: 63 cannot be expressed as the sum of a non-negative integer and its reverse so we return false.

Example 3:

Input: num = 181
Output: true
Explanation: 140 + 041 = 181 so we return true. Note that when a number is reversed, there may be leading zeros.

Constraints:

  • 0 <= num <= 105

Asked at 1 company

Hints open one at a time

Hint 1
The constraints are small enough that we can check every number.
Hint 2
To reverse a number, first convert it to a string. Then, create a new string that is the reverse of the first one. Finally, convert the new string back into a number.
3:42
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def sumOfNumberAndReverse(self, num: int) -> bool:
3
Starter codePython 3Spaces: 4
Examples
Input
443
Input
63
Input
181
Your code is saved on this device.Solution