当前位置:网站首页>模拟卷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,如果有错请留言,我看到了会修改的!谢谢!
边栏推荐
- 【Postman】动态变量(也称Mock函数)
- Isam2 and incrementalfixedlagsmooth instructions in gtsam
- Nodejs realizes the third-party login of Weibo
- JDBC Requset 对应内容及功能介绍
- Thoughts on data security (Reprint)
- Function of activation function
- Embedded point test of app
- 黑猫带你学UFS协议第8篇:UFS初始化详解(Boot Operation)
- 二维码的前世今生 与 六大测试点梳理
- Application of Lie group in gtsam
猜你喜欢

Manage configuration using Nacos

ESP32 ESP-IDF看门狗TWDT

Manhattan distance and Manhattan rectangle - print back font matrix
![[postman] collections - run the imported data file of the configuration](/img/85/7ac9976fb09c465c88f376b2446517.png)
[postman] collections - run the imported data file of the configuration

Fault, error, failure of functional safety

Significance of unit testing

曼哈顿距离与曼哈顿矩形-打印回字型矩阵

【C语言】字符串左旋

Win10 cannot operate (delete, cut) files

Basic knowledge of error
随机推荐
使用Nacos管理配置
JDBC Requset 对应内容及功能介绍
Redis 核心技术与实战之 基本架构:一个键值数据库包含什么?
Réflexions sur la sécurité des données (réimpression)
What are the test sites for tunnel engineering?
10M25DCF484C8G(FPGA) AMY-6M-0002 BGA GPS模块
GTSAM中李群的運用
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
Application du Groupe Li dans gtsam
F - true liars (category and search set +dp)
Construction and integration of Zipkin and sleuth for call chain monitoring
LeetCode 739. 每日温度
Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
【Postman】Collections配置运行过程
IPv6 comprehensive experiment
Idea new UI usage
数字三角形模型 AcWing 1015. 摘花生
LeetCode 729. 我的日程安排表 I
曼哈顿距离和-打印菱形
Aike AI frontier promotion (2.13)