Skip to content

Commit b9a16e6

Browse files
author
MouCoder
committed
回文数(提交成功代码)
1 parent 4dfce58 commit b9a16e6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

HuiWenShu/Solution.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

HuiWenShu/Test.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
}

0 commit comments

Comments
 (0)