786. 第 K 个最小的素数分数

exiaohu 于 2021-11-29 发布

题目链接:786. 第 K 个最小的素数分数

解法一

暴力方法,一行代码。

import heapq
from itertools import combinations
from typing import List


class Solution:
    def kthSmallestPrimeFraction(self, arr: List[int], k: int) -> List[int]:
        return list(heapq.nsmallest(k, combinations(arr, 2), key=lambda item: item[0] / item[1])[-1])

解法二