Longest Palindromic Prefix Leetcode, The time complexity is O (n 2), and the space complexity is O (1).