当前位置:网站首页>Minimum score of one question per day
Minimum score of one question per day
2022-06-13 01:15:00 【Roam-G】
Medium difficulty
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
Pass times 22,357
Submit the number 33,159

Java
```
class Solution {
public List<String> simplifiedFractions(int n) {
List<String> ans = new ArrayList<String>();
for (int denominator = 2; denominator <= n; ++denominator) {
for (int numerator = 1; numerator < denominator; ++numerator) {
if (gcd(numerator, denominator) == 1) {
ans.add(numerator + "/" + denominator);
}
}
}
return ans;
}
public int gcd(int a, int b) {
return b != 0 ? gcd(b, a % b) : a;
}
}
python
class Solution:
def simplifiedFractions(self, n: int) -> List[str]:
return [f"{numerator}/{denominator}" for
denominator in range(2, n + 1) for
numerator in range(1, denominator)
if gcd(denominator, numerator) == 1]

边栏推荐
- Rasa dialogue robot helpdesk (III)
- Facial expression recognition dataset
- Matrix fast power
- 切线与切平面
- RSA encryption colloquial explanation
- 707. design linked list
- [latex] insert picture
- How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic returns of vrsi, bbiboll, WR, bias and RSI indicators
- [Stanford Jiwang cs144 project] lab1: streamreassembler
- ES6 deconstruction assignment
猜你喜欢
随机推荐
Leetcode question brushing 04 string
leetode. 242. valid Letter heteronyms
Unitywebrequest asynchronous Download
[projet cs144 de Stanford Computing Network] lab1: Stream reassembler
深度学习模型剪枝
Introduction to convolutional neural network
Pipeline pipeline project construction
Lecture on Compilation Principles
Et5.0 simply transform referencecollectorieditor
Leetcode-16- sum of the nearest three numbers (medium)
The tle4253gs is a monolithic integrated low dropout tracking regulator in a small pg-dso-8 package.
Sequence table - find main element
Wal mechanism of MySQL
五篇经典好文,值得一看(2)
How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic returns of BBI, MTM, obv, CCI and priceosc indicators
How to handle different types of data
Leetcode question brushing 03 stack
Ecological convergence NFT attacks, metaverse ape leads the new paradigm revolution of Web 3.0 meta universe
Answer to matrix theory of Nanjing University of Aeronautics and Astronautics
3623. Merge two ordered arrays
![[JS component] browse progress bar](/img/cb/913f446db2cacdb965a3bf619aa478.jpg)








