-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.java
More file actions
37 lines (30 loc) · 928 Bytes
/
Palindrome.java
File metadata and controls
37 lines (30 loc) · 928 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
31
32
33
34
35
36
37
// Given an integer x, return true if x is palindrome integer.
// An integer is a palindrome when it reads the same backward as forward.
// For example, 121 is a palindrome while 123 is not.
// Input: x = 121
// Output: true
// Explanation: 121 reads as 121 from left to right and from right to left.
// Input: x = -121
// Output: false
// Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
class Solution {
public boolean isPalindrome(int x) {
int number =x;
int reminder;
int reveresed=0;
while(number!=0)
{
reminder=number%10;
reveresed=reveresed*10 +reminder;
number=number/10;
}
if(x==reveresed && reveresed >= 0)
{
return true;
}
else
{
return false;
}
}
}