Skip to content

Commit 710fdb5

Browse files
authored
Create simplified-fractions.py
1 parent b67102c commit 710fdb5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Python/simplified-fractions.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(n^2 * logn)
2+
# Space: O(n^2)
3+
4+
import fractions
5+
6+
class Solution(object):
7+
def simplifiedFractions(self, n):
8+
"""
9+
:type n: int
10+
:rtype: List[str]
11+
"""
12+
lookup = set()
13+
for b in xrange(1, n+1):
14+
for a in xrange(1, b):
15+
g = fractions.gcd(a, b)
16+
lookup.add((a//g, b//g))
17+
return ["{}/{}".format(*fr) for fr in lookup]

0 commit comments

Comments
 (0)