活跃农民
- 积分
- 662
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2018-1-16
- 最后登录
- 1970-1-1
|
1111111111111111111111111111111111111111111111
class Solution():
def fun(self, head):
self.head = head
def recur(node: Node, flag): # if flag is true, you need to delete next node, if next node != head!
if node.next == head:
return
if not flag:
recur(node.next, not flag)
else:
# delete the node
node.next = node.next.next
recur(node, not flag)
'''
node should not change, because you have already deleted the next node
'''
return
recur(head, True)
return
2222222222222222222222222222222222222222222222222222222
class Solution():
def fun(self, s: str):
lis = []
p0 = 0
while p0 < len(s):
print(p0)
i_next = p0 + 1
if i_next < len(s) and s[i_next] == s[p0]:
p1 = p0 + 1
# how many repeating element
while s[p1] == (s[p1 + 1] if p1 + 1 < len(s) else 1):
print(p1)
p1 += 1
if p1 - p0 + 1 >= 2:
lis.append((p0, p1))
p0 = p1 + 1
else:
p0 += 1
return lis
a = Solution()
print(a.fun('abbbcc'))
class Solution1():
def dfs(self, s, lis, dic):
self.dic = dic
s = list(s)
def recur(s, lis):
if ''.join(s) in dic:
return True
if lis == []:
return False
start, end = lis.pop()
for i in range(start, end):
s.pop(start)
if recur(s, lis):
return True
return False
return recur(s, lis)
lis = a.fun("heelllloo")
dic = {"hello"}
b = Solution1()
print(b.dfs("heelllloo", lis, dic))
|
|