当前位置:网站首页>模拟卷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,如果有错请留言,我看到了会修改的!谢谢!
边栏推荐
猜你喜欢

【微信小程序】搭建开发工具环境

JMeter做接口测试,如何提取登录Cookie

数学三大核心领域概述:代数
![Buuctf-[[gwctf 2019] I have a database (xiaoyute detailed explanation)](/img/2c/43ce298794589c5282edda94161d62.jpg)
Buuctf-[[gwctf 2019] I have a database (xiaoyute detailed explanation)

二维码的前世今生 与 六大测试点梳理
![[API interface tool] Introduction to postman interface](/img/03/c1541fca65dd726fd4bdc8793b605e.png)
[API interface tool] Introduction to postman interface

Detailed explanation of BF and KMP

LeetCode 1200. 最小绝对差

Caused by:org. gradle. api. internal. plugins . PluginApplicationException: Failed to apply plugin

Manhattan distance sum - print diamond
随机推荐
nodejs实现微博第三方登录
多线程应用的测试与调试
Eigen稀疏矩阵操作
B - The Suspects
Buuctf-[bjdctf2020]zjctf, but so (xiaoyute detailed explanation)
What are the test sites for tunnel engineering?
Overview of three core areas of Mathematics: algebra
Postman核心功能解析-参数化和测试报告
[postman] dynamic variable (also known as mock function)
Amazon Engineer: eight important experiences I learned in my career
Manhattan distance sum - print diamond
【C语言】字符串左旋
[leetcode] day96 - the first unique character & ransom letter & letter ectopic word
Redis 核心技术与实战之 基本架构:一个键值数据库包含什么?
Testing and debugging of multithreaded applications
Company video accelerated playback
Cannot create PoolableConnectionFactory (Could not create connection to database server. 错误
Luogu p1460 [usaco2.1] healthy Holstein cows
Function of activation function
Basic knowledge of error