Created
February 6, 2020 08:59
-
-
Save qodirovshohijahon/1e6bc3534b962b7106c3b8dcf29d014a to your computer and use it in GitHub Desktop.
In this example you can see solving palindrom numbers in another way.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} x | |
* @return {boolean} | |
*/ | |
var isPalindrome = function(x) { | |
let sum = 0, n, m = x; | |
if (x < 0) return false; | |
while (x != 0 ) { | |
sum = sum * 10 + x % 10;; | |
x = Math.floor (x / 10); | |
} | |
return sum == m ? true : false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment