public static boolean isPalindrome(String s) { int l = 0, r = s.length() - 1; s = s.toLowerCase(); if (s.isEmpty()) return true; while (l <= r) { while (l < r && !Character.isLetterOrDigit(s.charAt(l))) l++; while (l < r && !Character.isLetterOrDigit(s.charAt(r))) r--; if (s.charAt(l) != s.charAt(r)) return false; l++; r--; } return true; }Input: "madam"