/* 自定義代碼塊樣式 */

herrDeng網內搜尋

自訂搜尋

Ads

2025年9月2日 星期二

Py3 C++排序loop解Leetcode 3025 3027 Find the Number of Ways to Place People


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

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章