File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ package LeetCode .HuiWenShu ;
2+
3+ import java .util .ArrayList ;
4+
5+ public class Solution {
6+ public boolean isPalindrome (int x ) {
7+ if (x < 0 )
8+ return false ;
9+ else {
10+ int y = x ;
11+ ArrayList <Integer > arry = new ArrayList <>();
12+ int i = 0 ,n =1 ;
13+ int result =0 ;
14+ while (x !=0 ){
15+ arry .add (x %10 );
16+ x /= 10 ;
17+ }
18+ for (int j = arry .size ()-1 ;j >=0 ;j --) {
19+ result += (arry .get (j ))*n ;
20+ n *= 10 ;
21+ }
22+ if (y == result )
23+ return true ;
24+ else
25+ return false ;
26+ }
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ package LeetCode .HuiWenShu ;
2+
3+ public class Test {
4+ public static void main (String [] args ) {
5+ Solution sol = new Solution ();
6+ System .out .println (sol .isPalindrome (121 ));
7+ }
8+ }
You can’t perform that action at this time.
0 commit comments