igor.sorokin66
BAN USERimport re
def checkRepeatChars(word):
while len(word) != 0:
if word[0] == word[1]:
word = re.sub(r'^%s+' % word[0],"",word)
else:
return False
return True
print(checkRepeatChars("bbbblllllllooooooooobbbbbbbbb"))
Did it in python using a binary tree and traversing it recursively with depth first search.
class Node:
def __init__(self,val,next):
self._val = val
self._next = next
def setVal(self, val):
self._val = val
def getVal(self):
return self._val
def setNext(self, next):
self._next = next
def getNext(self):
return self._next
def allPossiCaseCombos(str):
curr = Node(0,None)
root = Node(0,curr)
l = []
for c in str:
if c.isnumeric():
curr.setNext(Node(c, None))
else:
l.append(Node(c,None))
if c.istitle():
l.append(Node(c.lower(),None))
else:
l.append(Node(c.upper(),None))
curr.setNext(Node(l,None))
l = []
curr = curr.getNext()
return root
curr = allPossiCaseCombos("ab6cd").getNext().getNext()
def go(curr,str):
if curr.getNext() == None:
if isinstance(curr.getVal(),list):
for n in curr.getVal():
print(str+n.getVal())
else:
print(str+curr.getVal())
return
if isinstance(curr.getVal(),list):
for n in curr.getVal():
go(curr.getNext(),str+n.getVal())
else:
go(curr.getNext(),str+curr.getVal())
go(curr,"")
- igor.sorokin66 February 07, 2015