MemotivaLeetCode Patterns Flashcards: Two Pointers, Sorted Arrays, Pair Finding, Palindromes

How do you check if a string is a palindrome using two pointers?

LeetCode Patterns Flashcards: Two Pointers, Sorted Arrays, Pair Finding, Palindromes

Аудио-карточка · 0:25

Nortren·

How do you check if a string is a palindrome using two pointers?

0:25

Place one pointer at the start and one at the end of the string. Compare the characters at both pointers. If they match, move both pointers inward. If they do not match, the string is not a palindrome. Continue until the pointers meet or cross. This runs in O of n time and O of one space. For the variant "valid palindrome" that ignores non-alphanumeric characters and case, skip characters that are not letters or digits during traversal and compare lowercase versions.
neetcode.io