350.两个数组的交集:
def intersect(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: List[int]
"""
res=[]
if len(nums1)>len(nums2):
for i in nums2:
for j in range(len(nums1)):
if i==nums1[j]:
res.append(i)
del nums1[j]
break
else:
for i in nums1:
for j in range(len(nums2)):
if i==nums2[j]:
res.append(i)
del nums2[j]
break
return res
121.买股票的最佳时机:
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
minbuy=999999
maxz=0
for i in range(len(prices)):
if prices[i] < minbuy:
minbuy=prices[i]
if prices[i]-minbuy>maxz:
maxz=prices[i]-minbuy
return maxz