File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
main/java/s0009.palindrome.number
test/java/s0009.palindrome.number Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ package s0009 .palindrome .number ;
2+
3+ public class Solution {
4+ public boolean isPalindrome (int x ) {
5+ if (x < 0 ) {
6+ return false ;
7+ }
8+ int rev = 0 ;
9+ int localX = x ;
10+ while (localX > 0 )
11+ {
12+ rev *= 10 ;
13+ rev += localX % 10 ;
14+ localX /= 10 ;
15+ }
16+ return rev == x ;
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ package s0009 .palindrome .number ;
2+
3+ import static org .hamcrest .CoreMatchers .equalTo ;
4+ import static org .hamcrest .MatcherAssert .assertThat ;
5+ import org .junit .Test ;
6+
7+ public class SolutionTest {
8+ @ Test
9+ public void isPalindrome () {
10+ assertThat (new Solution ().isPalindrome (121 ), equalTo (true ));
11+ }
12+ }
You can’t perform that action at this time.
0 commit comments