Good post. Really liked various ways you have noted. I will suggest one more. It should work too. Let me know...
Use two pointers starting from 0th and (string.length-1)th index, increase one and decrease the other respectively, till they meet at the center and compare characters at those pointers. If they match continue, else return false.
The advantage you gain is no excess space is required.
I am a Software Engineer and Developer Advocate who loves sharing knowledge via writing, videos, mentorship, and working out. Please Subscribe: https://www.youtube.com/channel/UCcz5Bvr4kGHPFAjvnRhIQ4g
Good post. Really liked various ways you have noted. I will suggest one more. It should work too. Let me know...
Use two pointers starting from 0th and (string.length-1)th index, increase one and decrease the other respectively, till they meet at the center and compare characters at those pointers. If they match continue, else return false.
The advantage you gain is no excess space is required.
That is what I would do.
That approach is also useful to reverse arrays, just swap
0th <-> (len-1)th
and so on.I will definitely check it out. Sounds like divide-and-conquer. Lol