Skip to content

Commit 4f1bcb5

Browse files
author
changhongyuan
committed
第9题
1 parent 32a6480 commit 4f1bcb5

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

.idea/leetcode/editor.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。
2+
//
3+
// 示例 1:
4+
//
5+
// 输入: 121
6+
//输出: true
7+
//
8+
//
9+
// 示例 2:
10+
//
11+
// 输入: -121
12+
//输出: false
13+
//解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。
14+
//
15+
//
16+
// 示例 3:
17+
//
18+
// 输入: 10
19+
//输出: false
20+
//解释: 从右向左读, 为 01 。因此它不是一个回文数。
21+
//
22+
//
23+
// 进阶:
24+
//
25+
// 你能不将整数转为字符串来解决这个问题吗?
26+
// Related Topics 数学
27+
// 👍 1336 👎 0
28+
29+
package com.changhongyuan.leetcode.editor.cn;
30+
class PalindromeNumber{
31+
//leetcode submit region begin(Prohibit modification and deletion)
32+
class Solution {
33+
public boolean isPalindrome(int x) {
34+
int y = 0;
35+
int xBe = x;
36+
while (x > 0) {
37+
y = y * 10 + x % 10;
38+
x = x / 10;
39+
}
40+
return xBe == y;
41+
}
42+
}
43+
//leetcode submit region end(Prohibit modification and deletion)
44+
45+
public static void main(String[] args) {
46+
Solution solution = new PalindromeNumber().new Solution();
47+
System.out.println(solution.isPalindrome(-123124));
48+
}
49+
}
Binary file not shown.

0 commit comments

Comments
 (0)