Leet Code 9 Palindrome Number - 回文数 - Java
2016-06-06 00:00
435 查看
摘要: Leet Code 9 Palindrome Number - 回文数 - Java
问题原始链接 https://leetcode.com/problems/palindrome-number
判断一个整数是否是回文数。负数不认为是回文数。
例子1:输入101,返回true。
例子2:输入10,返回false。
问题原始链接 https://leetcode.com/problems/palindrome-number
判断一个整数是否是回文数。负数不认为是回文数。
例子1:输入101,返回true。
例子2:输入10,返回false。
[code=language-java]public class Solution { public boolean isPalindrome(int x) { if (x < 0) { return false; } int div = 1; while (x / div >= 10) { div *= 10; } while (x != 0) { int l = x / div; int r = x % 10; if (l != r) { return false; } x = (x % div) / 10; div /= 100; } return true; } }
相关文章推荐
- C++回文数及素数问题计算方法
- 用while判断输入的数字是否回文数的简单实现
- php找出指定范围内回文数且平方根也是回文数的方法
- leetcode 179 Largest Number
- leetcode 24 Swap Nodes in Pairs
- leetcode 2 Add Two Numbers 方法1
- leetcode 2 Add Two Numbers 方法2
- leetcode----Longest Substring Without Repeating Characters
- [LeetCode]47 Permutations II
- [LeetCode]65 Valid Number
- [LeetCode]123 Best Time to Buy and Sell Stock III
- [LeetCode] String Reorder Distance Apart
- [LeetCode] Sliding Window Maximum
- [LeetCode] Find the k-th Smallest Element in the Union of Two Sorted Arrays
- [LeetCode] Determine If Two Rectangles Overlap
- [LeetCode] A Distance Maximizing Problem
- leetcode_linearList
- leetcode_linearList02
- 021-Merge Two Sorted Lists(合并两个排好序的单链表);leetcode
- LeetCode[Day 1] Two Sum 题解