herrDeng網內搜尋

自訂搜尋

Ads

2025年2月6日 星期四

排列組合Python解Leetcode 1726 Tuple with Same Product


本片展示如何理解這題排列組合實質內容,以及如何完成 1 行Python程式碼。
[Py3 code請進]

-----------------------
This film shows how to undertand the combinatorial content for this question, and how write it in 1-line Python code.

class Solution:
    def tupleSameProduct(self, nums: List[int]) -> int:
        return sum(f*(f-1)*4 for f in (Counter(x*y for x, y in combinations(nums, 2))).values())

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章