## 9. Palindrome Number 原

datacube

``````
/**
* Created by lifei on 16/6/28.
*
* 从两头依次取数字比较，向中间推进。
*/
public class IsPalindrome {

public static void main(String[] args) {
IsPalindrome ip = new IsPalindrome();
System.out.println(ip.isPalindrome(1221));

}
public boolean isPalindrome(int x) {
if (x < 0)
return false;
//calcu the length of digit
int len = 1;
while (x / len >= 10) {   //得到最大的除数
len *= 10;
}
while (x != 0) {
int left = x / len;
int right = x % 10;

if (left != right)
return false;
//remove the head and tail digit
x = (x % len) / 10;    //把余数作为下一次遍历对象   x%len去掉高位,  再 /10去低位
len /= 100;            //减少len的步长
}
return true;
}
}
``````

### datacube

leetcode-9 Palindrome Number 回文

layout: post title: "leetcode-9 Palindrome Number 回文" tags: - leetcode - python - algorithm - Palindrome 回文 Palindrome Number 判断一个整数是否是回文数。回文数是指正序（从左向......

sz88888
04/10
0
0
Leetcode 9. Palindrome Number

SnailTyan
2018/08/02
0
0
LeetCode 9. Number(回文数)

dby_freedom
2018/09/04
0
0
LeetCode 9. Palindrome Number

Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. 判断一个整数是不是回文的 Follow up: Coud you solve it witho......

2018/11/13
0
0

Problem 1. Multiples of 3 and 5 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of......

prpr
2014/03/13
4.2K
3

code-ortaerc
25分钟前
4
0

[TOC] 1.1.1标签操作v-text&v-html v-text：会把data中绑定的数据值原样输出。 v-html：会把data中值输出，且会自动解析html代码 <!--可以将指定的内容显示到标签体中--><标签 v-text=""></......

57分钟前
7
0
VMware vSphere的两种RDM磁盘

10
0
【AngularJS学习笔记】02 小杂烩及学习总结

14
0
Linux 内核的五大创新

18
0