- Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathPalind_Part.py
More file actions
Latest commit
24 lines (21 loc) · 795 Bytes
/
Copy pathPalind_Part.py
File metadata and controls
24 lines (21 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
classSolution:
defpalindromicPartition(self, string):
# code here
a=string
cut= [0foriinrange(len(a))]
palindrome= [[Falseforiinrange(len(a))] forjinrange(len(a))]
foriinrange(len(a)):
minCut=i
forjinrange(i+1):
if (a[i] ==a[j] and (i-j<2orpalindrome[j+1][i-1])):
palindrome[j][i] =True
minCut=min(minCut,0ifj==0else (cut[j-1] +1))
cut[i] =minCut;
returncut[len(a) -1]
# Payel - AIML TMSL
if__name__=='__main__':
t=int(input())
for_inrange (t):
string=input()
ob=Solution()
print(ob.palindromicPartition(string))