-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq2.cpp
More file actions
30 lines (28 loc) · 687 Bytes
/
q2.cpp
File metadata and controls
30 lines (28 loc) · 687 Bytes
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
/* Determine whether an integer is a palindrome. Do this without extra space.
A palindrome integer is an integer x for which reverse(x) = x where reverse(x) is x with its digit reversed.
Negative numbers are not palindromic.*/
int Solution::isPalindrome(int A)
{
if(A<0) return 0;
//if(A==0) return 0;
int cp=0; int x=A;
while(x!=0)
{
cp++;
x=x/10;
}
x=A; int i=0; int tot=cp; cp--;
while(i<tot/2)
{
int a1=x/(pow(10,cp));
int a2=A%10;
A=A/10;
int t=pow(10,cp);
cp--;
x=x%t;
if(a1!=a2)
return 0;
i++;
}
return 1;
}