Performance of Various Methods to Test for a Palindrome [Python]

前端 未结 4 1876
梦谈多话
梦谈多话 2021-01-21 09:29

Today, I was fooling around with a couple of programming puzzles. Faced with the task of testing a string to see whether or not it is a palindrome, I conceived of several ways t

4条回答
  •  生来不讨喜
    2021-01-21 10:22

    You can't do a palindrome check faster than O(n) (n being the length of the input string). Any extra effort (stacks, reversing the string etc.) won't give you any perforce improvement, it only costs memory.

提交回复
热议问题