def reversePrint(self, head):"""
:type head: ListNode
:rtype: List[int]"""
res =[]whilehead:
res.append(head.val)
head = head.next
return res[::-1]
最大上升子序列
def maxProfit(self, prices):"""
:type prices: List[int]:rtype: int
"""
top = prices[len(prices)-1]
pre_max=0
res =0for i inrange(len(prices)-1,-1,-1):
res =max(res, top-prices[i])
pre_max =min(pre_max, prices[i])
top =max(top, prices[i])return res
合并表记录
def func(n,datas):
data_dict =dict()for data indatas:
m,n =map(int,data.split())if m indata_dict:
data_dict[m]+= n
else:
data_dict[m]= n
dic =sorted(data_dict.keys())