We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。
Input: 121 Output: true
Input: -121 Output: false Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Input: 10 Output: false Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
The text was updated successfully, but these errors were encountered:
/** * @param {number} x * @return {boolean} */ var isPalindrome = function(x) { if (x === 0) { return true; } if (x < 0 || x % 10 === 0) { return false; } let reverseNum = 0; while(x > reverseNum) { reverseNum = reverseNum * 10 + x % 10; x = Math.floor(x / 10); } return x === reverseNum || x === Math.floor(reverseNum / 10); };
function isPalindrome(x: number): boolean { if (x === 0) { return true; } if (x < 0 || x % 10 === 0) { return false; } let reverseNum = 0; while(x > reverseNum) { reverseNum = reverseNum * 10 + x % 10; x = Math.floor(x / 10); } return x === reverseNum || x === Math.floor(reverseNum / 10); };
Sorry, something went wrong.
No branches or pull requests
9. Palindrome Number
判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。
Example 1
Example 2
Example 3
Follow up
The text was updated successfully, but these errors were encountered: