当前位置:网站首页>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)
边栏推荐
- F - Two Exam(AtCoder Beginner Contest 238)
- Warning using room database: schema export directory is not provided to the annotation processor so we cannot export
- Sword finger offer 05 Replace spaces
- 二十六、文件系统API(设备在应用间的共享;目录和文件API)
- ALU逻辑运算单元
- 剑指 Offer 05. 替换空格
- Zheng Qing 21 ACM is fun. (3) part of the problem solution and summary
- 【Jailhouse 文章】Jailhouse Hypervisor
- Detailed explanation of expression (csp-j 2021 expr) topic
- 剑指 Offer 53 - I. 在排序数组中查找数字 I
猜你喜欢
Sword finger offer 06 Print linked list from beginning to end
剑指 Offer 35.复杂链表的复制
Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
YOLOv5-Shufflenetv2
[jailhouse article] jailhouse hypervisor
6. Logistic model
Talking about JVM (frequent interview)
Gbase database helps the development of digital finance in the Bay Area
R语言【数据集的导入导出】
随机推荐
Wazuh開源主機安全解决方案的簡介與使用體驗
Analysis of backdoor vulnerability in remote code execution penetration test / / phpstudy of national game title of national secondary vocational network security B module
A problem and solution of recording QT memory leakage
2022年贵州省职业院校技能大赛中职组网络安全赛项规程
中职网络安全技能竞赛——广西区赛中间件渗透测试教程文章
软件测试 -- 0 序
Simply sort out the types of sockets
【Jailhouse 文章】Performance measurements for hypervisors on embedded ARM processors
Codeforces Round #732 (Div. 2) D. AquaMoon and Chess
SAP method of modifying system table data
Drawing dynamic 3D circle with pure C language
The connection and solution between the shortest Hamilton path and the traveling salesman problem
How to adjust bugs in general projects ----- take you through the whole process by hand
Kubedm series-00-overview
Convolution neural network -- convolution layer
[jailhouse article] jailhouse hypervisor
[jailhouse article] look mum, no VM exits
Remote upgrade afraid of cutting beard? Explain FOTA safety upgrade in detail
kubeadm系列-00-overview
Transform optimization problems into decision-making problems