当前位置:网站首页>One question per day 1447 Simplest fraction
One question per day 1447 Simplest fraction
2022-07-05 05:42:00 【A big pigeon】
topic : Give you an integer n
, Please return to all 0 To 1 Between ( barring 0 and 1) Satisfy that the denominator is less than or equal to n
Of Simplest fraction . The score can be in the form of arbitrarily Sequential return .
Explain : Find the simplest fraction , The greatest common divisor equivalent to denominator and numerator is 1.
class Solution:
def simplifiedFractions(self, n: int) -> List[str]:
res = []
for i in range(2,n+1):
for j in range(1,i):
if gcd(i,j) == 1:
ff = f"{j}/{i}"
res.append(ff)
return res
greatest common divisor gcd(a,b) yes Python Built in functions , You can use it directly .
gcd Recursive implementation of
def gcd(a,b):
return a if b == 0 else gcd(b, a%b)
边栏推荐
猜你喜欢
Sword finger offer 05 Replace spaces
[jailhouse article] look mum, no VM exits
剑指 Offer 58 - II. 左旋转字符串
lxml. etree. XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
2017 USP Try-outs C. Coprimes
【Jailhouse 文章】Look Mum, no VM Exits
[jailhouse article] jailhouse hypervisor
剑指 Offer 53 - II. 0~n-1中缺失的数字
6. Logistic model
网络工程师考核的一些常见的问题:WLAN、BGP、交换机
随机推荐
剑指 Offer 04. 二维数组中的查找
【云原生】微服务之Feign自定义配置的记录
Some common problems in the assessment of network engineers: WLAN, BGP, switch
全排列的代码 (递归写法)
Reader writer model
EOJ 2021.10 E. XOR tree
Sword finger offer 35 Replication of complex linked list
剑指 Offer 53 - I. 在排序数组中查找数字 I
Kubedm series-00-overview
Detailed explanation of expression (csp-j 2021 expr) topic
Analysis of backdoor vulnerability in remote code execution penetration test / / phpstudy of national game title of national secondary vocational network security B module
剑指 Offer 06.从头到尾打印链表
CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
Talking about JVM (frequent interview)
SAP method of modifying system table data
Introduction et expérience de wazuh open source host Security Solution
PC register
Cluster script of data warehouse project
剑指 Offer 09. 用两个栈实现队列
How can the Solon framework easily obtain the response time of each request?