当前位置:网站首页>Simulation volume leetcode [general] 1447 Simplest fraction
Simulation volume leetcode [general] 1447 Simplest fraction
2022-07-06 06:18:00 【Encounter simulation volume】
Summary : Simulation volume Leetcode Summary of questions
1447. Simplest fraction
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 .
Example 1:
Input :n = 2
Output :[“1/2”]
explain :“1/2” Is the only denominator less than or equal to 2 The simplest fraction of .
Example 2:
Input :n = 3
Output :[“1/2”,“1/3”,“2/3”]
Example 3:
Input :n = 4
Output :[“1/2”,“1/3”,“1/4”,“2/3”,“3/4”]
explain :“2/4” It's not the simplest fraction , Because it can be reduced to “1/2” .
Example 4:
Input :n = 1
Output :[]
Tips :
1 <= n <= 100
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/simplified-fractions
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Code :
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 turn 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')
remarks :
GitHub:https://github.com/monijuan/leetcode_python
CSDN Summary : Simulation volume Leetcode Summary of questions
You can add QQ Group communication :1092754609
leetcode_python.utils See the description on the summary page for details
First brush questions , Then generated by script blog, If there is any mistake, please leave a message , I see it will be revised ! thank you !
边栏推荐
- Database - current read and snapshot read
- 全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
- Hypothesis testing learning notes
- [postman] collections - run the imported data file of the configuration
- [postman] dynamic variable (also known as mock function)
- E - food chain
- 10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
- 10M25DCF484C8G(FPGA) AMY-6M-0002 BGA GPS模块
- Fault, error, failure of functional safety
- VINS-Mono: A Robust and Versatile Monocular Visual-Inertial State Estimator
猜你喜欢
技术分享 | 常见接口协议解析
D - How Many Answers Are Wrong
Buuctf-[gxyctf2019] no dolls (xiaoyute detailed explanation)
[wechat applet] build a development tool environment
Win10 cannot operate (delete, cut) files
F - True Liars (种类并查集+DP)
ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
Buuctf-[bjdctf2020]zjctf, but so (xiaoyute detailed explanation)
Application du Groupe Li dans gtsam
【eolink】PC客户端安装
随机推荐
Manhattan distance sum - print diamond
曼哈顿距离与曼哈顿矩形-打印回字型矩阵
MFC关于长字符串unsigned char与CString转换及显示问题
[API interface tool] Introduction to postman interface
On weak network test of special test
曼哈顿距离和-打印菱形
win10无法操作(删除、剪切)文件
[postman] test script writing and assertion details
模拟卷Leetcode【普通】1447. 最简分数
GTSAM中ISAM2和IncrementalFixedLagSmoother说明
Digital triangle model acwing 1015 Picking flowers
【Postman】动态变量(也称Mock函数)
还在为如何编写Web自动化测试用例而烦恼嘛?资深测试工程师手把手教你Selenium 测试用例编写
(中)苹果有开源,但又怎样呢?
【Postman】Collections配置运行过程
【微信小程序】搭建开发工具环境
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
使用Nacos管理配置
模拟卷Leetcode【普通】1062. 最长重复子串
Fault, error, failure of functional safety