Skip to content

Commit 772205f

Browse files
authored
Update 009_Palindrome_Number.java (qiyuangong#14)
* Added a simpler and easy to understand code in java, by @arun-aditya
1 parent 29c53b5 commit 772205f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

java/009_Palindrome_Number.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,26 @@ public boolean isPalindrome(int x) {
3838
}
3939
return true;
4040
}
41-
}
41+
}
42+
43+
// simpler code
44+
45+
class Solution {
46+
public boolean isPalindrome(int x) {
47+
int r,s=0,number=x;
48+
if(number<0){
49+
return false;
50+
}
51+
while (number!=0){
52+
r=number%10;
53+
s= s*10 +r;
54+
number/=10;
55+
}
56+
if (s==x){
57+
return true;
58+
}
59+
else {
60+
return false;
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)