We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent eb6d9c2 commit b95433dCopy full SHA for b95433d
PalindromeNumber.java
@@ -0,0 +1,25 @@
1
+/**
2
+ * Determine whether an integer is a palindrome. Do this without extra space.
3
+ */
4
+public class PalindromeNumber {
5
+ public static void main(String[] args){
6
+ System.out.println("1234321 is palindrome = " + isPalindrome(1234321));
7
+ System.out.println("1234567 is palindrome = " + isPalindrome(1234567));
8
+ }
9
+
10
+ private static boolean isPalindrome(int num) {
11
+ int div = 1;
12
+ while(num / div > 10){
13
+ div*=10;
14
15
16
+ while(num != 0){
17
+ int r = num % 10;
18
+ int l = num / div;
19
+ if(r != l) return false;
20
+ num = (num % div) / 10;
21
+ div /= 100;
22
23
+ return true;
24
25
+}
0 commit comments