Skip to content

Latest commit

 

History

History
22 lines (16 loc) · 412 Bytes

File metadata and controls

22 lines (16 loc) · 412 Bytes

04. Valid Palindrome

Link

bool isPalindrome(string s) {
  int p1 = 0, p2 = s.length() - 1;
  
  while(p1 < p2) {
    while(!isalpha(s[p1]) && !isdigit(s[p1]) && p1 < p2)
      p1++;
  
    while(!isalpha(s[p2]) && !isdigit(s[p2]) && p1 < p2)
      p2--;
    
    if(tolower(s[p1++]) != tolower(s[p2--]))
      return false;
  }

  return true;
}