-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindromic_partitions.py
More file actions
55 lines (44 loc) · 1.09 KB
/
palindromic_partitions.py
File metadata and controls
55 lines (44 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def checkPalindrome(s):
n = len(s)
i = 0
j = n-1
while i < j and s[i] == s[j]:
i += 1
j -= 1
if i < j:
return False
else:
return True
def addStrings(v, s, temp, index):
length = len(s)
current = temp
str = ''
# print(current)
if index == 0:
temp = []
for i in range(index,length):
str = str + s[i]
if checkPalindrome(str):
print("Found a palindrome {}".format(str))
temp.append(str)
print(temp)
if (i+1)<length:
addStrings(v,s,temp,i+1)
else:
print("Reached the end! with Temp = {}".format(temp))
v.append(list(temp))
print("Temp is now {}".format(current))
if len(current):
current.pop()
temp = current
else:
print("Not a palindrome {}".format(str))
def partition(text):
temp = []
v = []
addStrings(v,text,temp,0)
print(v)
def test():
text = "geeks"
# print(checkPalindrome("D"))
partition(text)