当前位置:网站首页>模拟卷Leetcode【普通】1447. 最简分数
模拟卷Leetcode【普通】1447. 最简分数
2022-07-06 06:15:00 【邂逅模拟卷】
汇总:模拟卷Leetcode 题解汇总
1447. 最简分数
给你一个整数 n ,请你返回所有 0 到 1 之间(不包括 0 和 1)满足分母小于等于 n 的 最简 分数 。分数可以以 任意 顺序返回。
示例 1:
输入:n = 2
输出:[“1/2”]
解释:“1/2” 是唯一一个分母小于等于 2 的最简分数。
示例 2:
输入:n = 3
输出:[“1/2”,“1/3”,“2/3”]
示例 3:
输入:n = 4
输出:[“1/2”,“1/3”,“1/4”,“2/3”,“3/4”]
解释:“2/4” 不是最简分数,因为它可以化简为 “1/2” 。
示例 4:
输入:n = 1
输出:[]
提示:
1 <= n <= 100
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/simplified-fractions
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
代码:
from leetcode_python.utils import *
class Solution:
def simplifiedFractions(self, n: int) -> List[str]:
return [f'{
a}/{
b}' for b in range(1,n+1) for a in range(1,b) if math.gcd(a,b)==1]
def test(data_test):
s = Solution()
data = data_test # normal
# data = [list2node(data_test[0])] # list转node
return s.getResult(*data)
def test_obj(data_test):
result = [None]
obj = Solution(*data_test[1][0])
for fun, data in zip(data_test[0][1::], data_test[1][1::]):
if data:
res = obj.__getattribute__(fun)(*data)
else:
res = obj.__getattribute__(fun)()
result.append(res)
return result
if __name__ == '__main__':
datas = [
[],
]
for data_test in datas:
t0 = time.time()
print('-' * 50)
print('input:', data_test)
print('output:', test(data_test))
print(f'use time:{
time.time() - t0}s')
备注:
GitHub:https://github.com/monijuan/leetcode_python
CSDN汇总:模拟卷Leetcode 题解汇总
可以加QQ群交流:1092754609
leetcode_python.utils详见汇总页说明
先刷的题,之后用脚本生成的blog,如果有错请留言,我看到了会修改的!谢谢!
边栏推荐
猜你喜欢

功能安全之故障(fault),错误(error),失效(failure)

【C语言】字符串左旋
![[eolink] PC client installation](/img/91/8b3c4264e544b14f926e91edddf18d.png)
[eolink] PC client installation
![[API interface tool] Introduction to postman interface](/img/03/c1541fca65dd726fd4bdc8793b605e.png)
[API interface tool] Introduction to postman interface

LeetCode 731. 我的日程安排表 II

联合索引的左匹配原则

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

MySQL之数据类型

CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全

GTSAM中李群的运用
随机推荐
Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
Overview of three core areas of Mathematics: geometry
[leetcode] day96 - the first unique character & ransom letter & letter ectopic word
SQLMAP使用教程(三)实战技巧二
[web security] nodejs prototype chain pollution analysis
数字三角形模型 AcWing 1015. 摘花生
CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
在线问题与离线问题
单元测试的意义
[postman] collections - run the imported data file of the configuration
Construction and integration of Zipkin and sleuth for call chain monitoring
IP day 16 VLAN MPLS configuration
Properties file
【微信小程序】搭建开发工具环境
selenium源码通读·9 |DesiredCapabilities类分析
调用链监控Zipkin、sleuth搭建与整合
数据库-当前读与快照读
Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
E - food chain
Postman核心功能解析-参数化和测试报告