File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ // TC: O(n)
2
+ // SC: O(n)
3
+ class Solution {
4
+ public boolean isPalindrome (String s ) {
5
+ String target = checkString (s );
6
+ return checkPalindrome (target );
7
+ }
8
+
9
+ private String checkString (String s ) {
10
+ StringBuilder sb = new StringBuilder ();
11
+ for (char c : s .toCharArray ()) {
12
+ if (c >= 'a' && c <= 'z' ) {
13
+ sb .append (c );
14
+ }
15
+ if (c >= 'A' && c <= 'Z' ) {
16
+ c = (char )(c - 'A' + 'a' );
17
+ sb .append (c );
18
+ }
19
+ if (c >= '0' && c <= '9' ) {
20
+ sb .append (c );
21
+ }
22
+ }
23
+ return sb .toString ();
24
+ }
25
+
26
+ private Boolean checkPalindrome (String target ) {
27
+ int start = 0 ;
28
+ int end = target .length () - 1 ;
29
+
30
+ while (start < end ) {
31
+ if (target .charAt (start ) != target .charAt (end )) return false ;
32
+ start += 1 ;
33
+ end -= 1 ;
34
+ }
35
+ return true ;
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments