Unofficial C Solution to Problem 2.7 in Cracking the Coding Interview (5th Edition)

11 May

There is a similar and easier question: how to check if an array is a palindrome? Or equivalently, how to check if a double linked list is a palindrome? The three solutions in the original question work well for these two similar questions. But in a better manner, we could set a pointer to the first item and a pointer to the last item. Then we would move the former pointer forward and the latter one backward, until they meet. Before each moving, we compare the value of two “current” items, and return false if they are different. When the two pointers meet, we could return true.

2 thoughts on “Unofficial C Solution to Problem 2.7 in Cracking the Coding Interview (5th Edition)

Leave a Reply

Your email address will not be published. Required fields are marked *