Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution(object):
- def isFirstLarger(dic1, dic2, start, end):
- if dic1 is None:
- return False
- if dic2 is None:
- return True
- lenfirst = dic1[end] - dic1[start]
- lensecond = dic2[end] - dic2[start]
- return lenfirst > lensecond
- def recursivePalindomeFinder(string, dictionary, largest, largestLen, start, end):
- if dictionary[start] == 0 or dictionary[end] == length:
- return
- if string[dictionary[start] - 1] == string[dictionary[end] + 1]:
- if dictionary[end] - dictionary[start] + 3 > largestLen:
- largestLen = dictionary[end] - dictionary[start] + 3
- largest = {start: dictionary[start] - 1, end: dictionary[end] + 1}
- else:
- return
- def longestPalindrome(self, s):
- start = 'start'
- end = 'end'
- largest = None
- largestLen = 0
- print 'ok upto this'
- for i in range(len(s)):
- curStr = s[i]
- dic = {start: i, end: i}
- if self.isFirstLarger(dic, largest, start, end):
- largest = dic
- largestLen = dic[end] - dic[start] + 1
- self.recursivePalindomeFinder(dic, largest, largestLen, start, end)
- sol = Solution()
- sol.longestPalindrome('101')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement