#2443
Sum of Number and Its Reverse
specialist · 940 · lc medium +32 · verified · 49.4% accepted · 279 likes · top 36%
Description
Given a non-negative integer num, return true if there exists a non-negative integer x such that x + reverse(x) == num, where reverse(x) is the integer obtained by reversing the digits of x.
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.
Code
1
2
3