Py3 C++排序loop解Leetcode 3025 3027 Find the Number of Ways to Place People
[Py3 code請進]
class Solution:
def numberOfPairs(self, P: List[List[int]]) -> int:
P.sort(key=lambda p:(-p[0], p[1]))
ans, n=0, len(P)
for i in range(n-1):
y, yi=1<<31, P[i][1]
for j in range(i+1, n):
yj=P[j][1]
if y>yj>=yi:
ans+=1
y=yj
return ans

沒有留言:
張貼留言