当前位置:网站首页>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]

边栏推荐
- Continue when the condition is not asked, execute the parameter you compare
- Quantitative investment traditional index investment decision vs Monte Carlo simulation method
- Status of the thread
- Method of cleaning C disk
- Pipeline流水线项目构建
- Remove duplicates from an ordered array
- [projet cs144 de Stanford Computing Network] lab1: Stream reassembler
- Jenkins持续集成操作
- RSA encryption colloquial explanation
- Google play console crash information collection
猜你喜欢
![[JS component] customize the right-click menu](/img/a3/4555619db17e4c398e72c7d6b12f5d.jpg)
[JS component] customize the right-click menu

五篇经典好文,值得一看(2)
![[Stanford Jiwang cs144 project] lab1: streamreassembler](/img/7b/fad18b68a6ee30d1dec4dad6273b98.png)
[Stanford Jiwang cs144 project] lab1: streamreassembler
![[JS component] browse progress bar](/img/cb/913f446db2cacdb965a3bf619aa478.jpg)
[JS component] browse progress bar

Leetcode question brushing 03 stack

Memory learning book reference

深度学习模型剪枝
![[JS component] dazzle radio box and multi box](/img/2a/00620bee312972db93e1db4313385f.jpg)
[JS component] dazzle radio box and multi box

使用Pygame创建一个简单游戏界面

Et5.0 configuring Excel
随机推荐
Pysmb usage
Ecological convergence NFT attacks, metaverse ape leads the new paradigm revolution of Web 3.0 meta universe
Wikipedia User Guide
Tangent and tangent plane
Vector|hdu-4841 round table questions
Jenkins continuous integration operation
Common skills of quantitative investment - index part 2: detailed explanation of BOL (Bollinger line) index, its code implementation and drawing
Leetcode-11- container with the most water (medium)
Addition and modification of JPA
A problem discovery and attempted solution to the strange stop of server script
Downloading wiki corpus and aligning with multilingual wikis
Common skills for quantitative investment - drawing 3: drawing the golden section line
redis
[latex] insérer une image
Et5.0 configuring Excel
Leetcode-78- subset (medium)
HashSet underlying source code
Quick power explanation
pycharm add configutions
Binary tree -- using hierarchical sequence and middle sequence to determine a tree