当前位置:网站首页>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)
边栏推荐
- R language [import and export of dataset]
- Little known skills of Task Manager
- Scope of inline symbol
- Bit mask of bit operation
- 每日一题-搜索二维矩阵ps二维数组的查找
- Codeforces Round #715 (Div. 2) D. Binary Literature
- Dichotomy, discretization, etc
- Using HashMap to realize simple cache
- Annotation and reflection
- Reader writer model
猜你喜欢
智慧工地“水电能耗在线监测系统”
Pointnet++ learning
On the characteristics of technology entrepreneurs from Dijkstra's Turing Award speech
YOLOv5-Shufflenetv2
Smart construction site "hydropower energy consumption online monitoring system"
Sword finger offer 04 Search in two-dimensional array
剑指 Offer 06.从头到尾打印链表
浅谈JVM(面试常考)
Sword finger offer 53 - ii Missing numbers from 0 to n-1
[cloud native] record of feign custom configuration of microservices
随机推荐
Csp-j-2020-excellent split multiple solutions
剑指 Offer 53 - I. 在排序数组中查找数字 I
个人开发的渗透测试工具Satania v1.2更新
Some common problems in the assessment of network engineers: WLAN, BGP, switch
On-off and on-off of quality system construction
Time of process
Use of room database
【Jailhouse 文章】Jailhouse Hypervisor
Brief introduction to tcp/ip protocol stack
Scope of inline symbol
SSH password free login settings and use scripts to SSH login and execute instructions
Remote upgrade afraid of cutting beard? Explain FOTA safety upgrade in detail
shared_ Repeated release heap object of PTR hidden danger
使用Electron开发桌面应用
Fried chicken nuggets and fifa22
Gbase database helps the development of digital finance in the Bay Area
Daily question - Search two-dimensional matrix PS two-dimensional array search
Web APIs DOM node
kubeadm系列-01-preflight究竟有多少check
R language [import and export of dataset]