GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/java/009_Palindrome_Number.java at master · pramodrj07/leetcode Expand file tree/ Copy path009_Palindrome_Number.javaMore file actions 41 lines (40 loc) · 1003 Bytes / Copy path009_Palindrome_Number.javaFile metadata and controls41 lines (40 loc) · 1003 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 38 39 40 41 class Solution { public boolean isPalindrome(int x) { if (x < 0) return false; int temp = x; int len = 0; while (temp != 0) { temp /= 10; len ++; } temp = x; int left, right; for (int i = 0; i < len / 2; i++) { right = temp % 10; left = temp / (int) Math.pow(10, len - 2 * i - 1); left = left % 10; if (left != right) return false; temp /= 10; } return true; } // Leetcode book public boolean isPalindrome(int x) { if (x < 0) return false; int div = 1; while ( x / div >= 10) { div *= 10; } while (x !=0) { int l = x / div; int r = x % 10; if (l != r) return false; // Remove left and right number x = (x % div) / 10; div /= 100; } return true; } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |