[leetcode/go] 5. Longest Palindromic Substring (Manacher)
·
Programming Languages/Go
Leetcode 5번 문제인데, palindrome(앞뒤로 읽어도 같은 문자열)인 substring 중 가장 긴 것을 찾는 문제이다.brute force랑 DP 정도를 떠올릴 수 있는데, Manacher's algorithm이라는 것이 있다. Manacher's algorithm으로 푼 go 코드이다. 무려 time complexity가 `O(n)`이다. ```gofunc longestPalindrome(s string) string { if len(s) // 구분자 삽입으로 홀/짝 통일 t := make([]rune, 0, 2*len(s)-1) for _, ch := range s { t = append(t, '#') t = append(t, ch) ..