leetcode-26双周赛-5397-最简分数

题目描述:

 

 

 

 提交:

class Solution:
    def simplifiedFractions(self, n: int) -> List[str]:
        
        def gcd(a, b):
            if b > a:
                return gcd(b, a)

            if a % b == 0:
                return b

            return gcd(b, a % b)
        
        res = set()
        if n == 1:
            return []
        for i in range(2,n+1):
            for j in range(1,i):
                if gcd(j,i) == 1:
                    res.add(str(j)+"/"+str(i))
        return list(res)

 

posted @ 2020-05-17 12:23  oldby  阅读(138)  评论(0编辑  收藏  举报