#125. Valid Palindrome [LeetCode Grind 75 in Java]

[Problem Link] https://leetcode.com/problems/valid-palindrome/

class Solution {
    public boolean isPalindrome(String s) {
        int n = s.length();

        //making the string as case insensitive 
        StringBuilder sb = new StringBuilder();
        for(char c : s.toCharArray()){
            c = Character.toLowerCase(c);
            if((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) sb.append(c);
        }

        //check palindrome
        int l = 0;
        n = sb.length();
        int r = n - 1;

        while(l <= r){
            if(sb.charAt(l) == sb.charAt(r)){
                l ++;
                r --;
            }else return false;
        }
        return true;       
    }
}