IT/[Everyday]Coding
the longest palindromic substring
Jang HyunWoong
2019. 3. 6. 11:16
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.
Example 1:
Input: "babad" Output: "bab" Note: "aba" is also a valid answer.
Example 2:
Input: "cbbd" Output: "bb"
Palindromic 이라는 것은 회기되는 단어를 이야기 한다.
예를들어 "토마토", "스위스" 와 같은 문장이다.
위 문제에서는 가장 긴 회기단어를 추출하라는 것이다.
Python Solution:
tmp1과 tmp2를 나누는 이유는 회기문장의 길이가 짝수일 경우를 대비해서 이다.
예를들어 "스위스"와 같은 경우는 tmp1에서 잡히고, "나나"같은 경우는 tmp2에서 잡을 수 있다.
반응형