-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathPalindromeNumberSln.cs
38 lines (36 loc) · 982 Bytes
/
PalindromeNumberSln.cs
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
/* ==============================================================================
* 功能描述:PalindromeNumberSln
* 创 建 者:gz
* 创建日期:2017/5/24 13:01:57
* ==============================================================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Math.Lib
{
/// <summary>
/// PalindromeNumberSln
/// </summary>
public class PalindromeNumberSln
{
public bool IsPalindrome(int x)
{
int palindromex = 0, tmp = x;
int sumbit = 0;
//calcuate bit count
while (tmp > 0)
{
sumbit++;
tmp /= 10;
}
tmp = x;
while (tmp > 0)
{
palindromex += tmp % 10 * (int)System.Math.Pow(10, --sumbit);
tmp /= 10;
}
return palindromex == x;
}
}
}