Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Python/Count_Primes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://leetcode.com/problems/count-primes/

class Solution:
def countPrimes(self, n: int) -> int:
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
sol = 0
for p in range(2, n):
if prime[p]:
sol += 1
return sol

17 changes: 17 additions & 0 deletions Python/Simplified_Fractions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Link: https://leetcode.com/problems/simplified-fractions/submissions/

class Solution:
def simplifiedFractions(self, n: int):
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
sol = []
for i in range(1, n + 1):
for j in range(1, i + 1):
if gcd(i, j) == 1:
if i == 1 and j == 1:
continue
ans = str(j) + '/' + str(i)
sol.append(ans)
return sol