package com.fishercoder.solutions;

/**Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

 For example,
 "A man, a plan, a canal: Panama" is a palindrome.
 "race a car" is not a palindrome.

 Note:
 Have you consider that the string might be empty? This is a good question to ask during an interview.

 For the purpose of this problem, we define empty string as valid palindrome.*/
public class _125 {

    public boolean isPalindrome(String s) {
        int i = 0;
        int j = s.length() - 1;
        char[] chars = s.toCharArray();
        while (i < j) {
            while (i < j && !Character.isLetterOrDigit(chars[i])) {
                i++;
            }
            while (i < j && !Character.isLetterOrDigit(chars[j])) {
                j--;
            }
            if (Character.toLowerCase(chars[i]) != Character.toLowerCase(chars[j])) {
                return false;
            }
            i++;
            j--;
        }
        return true;
    }

}

@@ -32,16 +32,44 @@
 ns;%0A%0A/**
+%0A * 125. Valid Palindrome%0A%0A 
 Given a 
@@ -382,17 +382,16 @@
 erview.%0A
-%0A
  For the
@@ -463,11 +463,14 @@
 ome.
+%0A 
 */%0A
+%0A
 publ
@@ -486,16 +486,50 @@
 _125 %7B%0A%0A
+  public static class Solution1 %7B%0A
     publ
@@ -566,26 +566,24 @@
  s) %7B%0A      
-  
 int i = 0;%0A 
@@ -581,18 +581,16 @@
  i = 0;%0A
-  
       in
@@ -611,18 +611,16 @@
 () - 1;%0A
-  
       ch
@@ -651,26 +651,24 @@
 ay();%0A      
-  
 while (i %3C j
@@ -667,28 +667,24 @@
 e (i %3C j) %7B%0A
-    
         whil
@@ -741,30 +741,24 @@
 %7B%0A          
-      
 i++;%0A       
@@ -754,34 +754,26 @@
 ++;%0A        
- 
-   %7D%0A    
+%7D%0A
         whil
@@ -830,30 +830,24 @@
 %7B%0A          
-      
 j--;%0A       
@@ -839,36 +839,32 @@
    j--;%0A        
-    
 %7D%0A            if
@@ -857,20 +857,16 @@
         
- 
-   
 if (Char
@@ -941,22 +941,16 @@
         
-      
 return f
@@ -959,28 +959,24 @@
 se;%0A        
-    
 %7D%0A          
@@ -969,37 +969,29 @@
   %7D%0A        
- 
-   
 i++;%0A
-    
         j--;
@@ -993,30 +993,26 @@
  j--;%0A      
-  %7D%0A  
+%7D%0A
       return
@@ -1024,11 +1024,14 @@
 ;%0A    %7D%0A
+  %7D
 %0A%7D%0A

refactor 125