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 97930f2 commit 1fd45c1Copy full SHA for 1fd45c1
Leetcode/easy/PalindromeNumber9.java
@@ -0,0 +1,30 @@
1
+package easy;
2
+
3
+public class PalindromeNumber9 {
4
5
+ public static boolean isPalindrome(int x) {
6
+ if (x < 0)
7
+ return false;
8
9
+ String num = String.valueOf(x);
10
11
+ int left = 0, right = num.length() - 1;
12
13
+ while (left < right) {
14
+ if (num.charAt(left) != num.charAt(right)) {
15
16
+ }
17
+ left++;
18
+ right--;
19
20
+ return true;
21
22
23
+ public static void main(String[] args) {
24
+ System.out.println(isPalindrome(121));
25
+ System.out.println(isPalindrome(-121));
26
+ System.out.println(isPalindrome(12321));
27
+ System.out.println(isPalindrome(10));
28
29
30
+}
0 commit comments