-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.回文数.c
63 lines (53 loc) · 1.04 KB
/
9.回文数.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* @lc app=leetcode.cn id=9 lang=c
*
* [9] 回文数
*
* https://leetcode-cn.com/problems/palindrome-number/description/
*
* algorithms
* Easy (56.84%)
* Likes: 910
* Dislikes: 0
* Total Accepted: 236.5K
* Total Submissions: 415K
* Testcase Example: '121'
*
* 判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。
*
* 示例 1:
*
* 输入: 121
* 输出: true
*
*
* 示例 2:
*
* 输入: -121
* 输出: false
* 解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。
*
*
* 示例 3:
*
* 输入: 10
* 输出: false
* 解释: 从右向左读, 为 01 。因此它不是一个回文数。
*
*
* 进阶:
*
* 你能不将整数转为字符串来解决这个问题吗?
*
*/
// @lc code=start
bool isPalindrome(int x)
{
long res = 0;
int y = x;
if (x < 0)
return false;
for (; y; res = res * 10 + y % 10, y /= 10);
return res == x;
}
// @lc code=end