160链表相交节点查找 python实现

"""
:rtype: ListNode
"""
a,b = 0,0
a,b = a+1,b+1
while p:
if p==q:
return p
p,q = p.next,q.next

return
'''
return
while p!=q:#并行比较链表节点value，复杂度O(N)
p = p.next if p else headB
q = q.next if q else headA
return p
'''

241 class Solution:
def diffWaysToCompute(self, input: str) -> List[int]:

#241 分治
res = []
ops = {'+':lambda x,y:x+y, '-':lambda x,y:x-y, '*':lambda x,y:x*y}
for indx in range(1,len(input)-1):
if input[indx] in ops.keys():
for left in self.diffWaysToCompute(input[:indx]):
for right in self.diffWaysToCompute(input[indx+1:]):
res.append(ops[input[indx]](left,right))

if not res:
res.append(int(input))

return res

242 字符串判断是否异位相同class Solution:
def isAnagram(self, s: str, t: str) -> bool:
if len(s)!=len(t):
return False
s_=list(s)
t_=list(t)
s_res=dict.fromkeys(s_,0)
t_res=dict.fromkeys(t_,0)
for i in s_:
if i in s_res.keys():
s_res[i]+=1
for j in t_:
if j in t_res.keys():
t_res[j]+=1
if len(s_res.items()&t_res.items())==len(s_res):
return True
else:
return False

232 栈队列
class MyQueue(object): def __init__(self): self.input = [] self.output = []
def push(self, x): self.input.append(x) def pop(self): if self.output: return
self.output.pop() else: while self.input: self.output.append(self.input.pop())
return self.output.pop() def peek(self): if self.output: return self.output[-1]
else: while self.input: self.output.append(self.input.pop()) return
self.output[-1] def empty(self): return len(self.input) == 0 and
len(self.output) == 0