LeetCode09-回文数
LeetCode09-回文数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public boolean isPalindrome(int x) { if (x == 0) { return true; } if (x < 0 || x % 10 == 0) { return false; } char[] chars = String.valueOf(x).toCharArray(); int left = 0; int right = chars.length - 1; while (left < right) { if (chars[left] != chars[right]) { return false; } left++; right--; } return true; }
|