topic:
Thought:
This is the beginningpopThought,But time complexity is too high,400ms,It is later changed to a list derivative。
I think of the senior said,pop()The running time is okay,But once the index is added inside,It will be particularly slow。
sorted and lambda Usage:
lambdayesPythonAnonymous function in。it’s here,lambda x: (x[1], x[0])Definitions a acceptance of an elementx(in this case,xyesrestaurantsA list in the list)And return a tuple(x[1], x[0])The function。
this means,Sort首先基于每个子列表的第二个元素x[1],Then based on this basisx[0]。in other words,It first followsx[1]进行Sort,ifx[1]same,According tox[0]进行Sort。
1 | while ind < len(restaurants): |
Code:
1 | class Solution: |