Skip to content

Commit 2f3f186

Browse files
refactor 9
1 parent 39bf81e commit 2f3f186

File tree

2 files changed

+1
-26
lines changed

2 files changed

+1
-26
lines changed

src/main/java/com/fishercoder/solutions/_9.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,9 @@
1717
*/
1818
public class _9 {
1919

20-
public static class Solution1 {
21-
public boolean isPalindrome(int x) {
22-
if (x == 0) {
23-
return true;
24-
}
25-
if (x < 0) {
26-
return false;
27-
}
28-
int rev = 0;
29-
int tmp = x;
30-
while (tmp != 0) {
31-
rev *= 10;
32-
rev += tmp % 10;
33-
tmp /= 10;
34-
}
35-
return rev == x;
36-
}
37-
}
38-
3920
/**credit: https://discuss.leetcode.com/topic/8090/9-line-accepted-java-code-without-the-need-of-handling-overflow
4021
* reversing only half and then compare if they're equal.*/
41-
public static class Solution2 {
22+
public static class Solution1 {
4223
public boolean isPalindrome(int x) {
4324
if (x < 0) {
4425
return false;

src/test/java/com/fishercoder/_9Test.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,30 @@
88

99
public class _9Test {
1010
private static _9.Solution1 solution1;
11-
private static _9.Solution2 solution2;
1211

1312
@BeforeClass
1413
public static void setup() {
1514
solution1 = new _9.Solution1();
16-
solution2 = new _9.Solution2();
1715
}
1816

1917
@Test
2018
public void test1() {
2119
assertEquals(false, solution1.isPalindrome(2147483647));
22-
assertEquals(false, solution2.isPalindrome(2147483647));
2320
}
2421

2522
@Test
2623
public void test2() {
2724
assertEquals(true, solution1.isPalindrome(0));
28-
assertEquals(true, solution2.isPalindrome(0));
2925
}
3026

3127
@Test
3228
public void test3() {
3329
assertEquals(true, solution1.isPalindrome(1));
34-
assertEquals(true, solution2.isPalindrome(1));
3530
}
3631

3732
@Test
3833
public void test4() {
3934
assertEquals(false, solution1.isPalindrome(10));
40-
assertEquals(false, solution2.isPalindrome(10));
4135
}
4236

4337
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy