资讯动态

leetcode 1447. Simplified Fractions 最简分数

发布时间:2026/8/20 4:10:06 来源:尧图企业网站定制
Problem: 1447. Simplified Fractions 最简分数分子分母的最大公约数等于1的分数才是最简真分数而可以约分的分数一定可以化成最简分数所以只需要保存最大公约数等于1的分数!1的分数不需要保存Codeclass Solution { public: int gcd(int a, int c) { if(c 0) return a; return gcd(c, a % c); } vectorstring simplifiedFractions(int n) { int d; string a, c, k /; vectorstring tr; for(int i n; i 2; i--) { a to_string(i); for(int j i - 1; j 1; j--) { d gcd(i, j); if(d1) tr.push_back(to_string(j) k a); } } return tr; } };

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价