-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindromeChecker.java
More file actions
46 lines (32 loc) · 894 Bytes
/
PalindromeChecker.java
File metadata and controls
46 lines (32 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.company;
public class PalindromeChecker {
public boolean check(String s){
int low=0;
int high=s.length()-1;
boolean equal = true;
while(low<high && equal){
if (s.charAt(low)!=s.charAt(high)) equal=false;
low++;
high--;
}
return equal;
}
public boolean check(int n){
int current = Math.abs(n);
if (current<10) return true;
int reverse = 0;
while (current>0){
reverse=reverse*10 + current%10;
current/=10;
}
return reverse==n;
}
public boolean lazycheck(String s){
StringBuilder sb = new StringBuilder(s);
return sb.equals(sb.reverse());
}
public boolean lazycheck(int n){
StringBuilder sb = new StringBuilder(n);
return sb.equals(sb.reverse());
}
}