We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a507d04 commit 22c0d6eCopy full SHA for 22c0d6e
my-submissions/m2523.py
@@ -0,0 +1,22 @@
1
+class Solution:
2
+ def closestPrimes(self, left: int, right: int) -> List[int]:
3
+ seive = [False, False] + [True] * (right - 1)
4
+
5
+ for factor in range(2, int(right ** 0.5) + 1) :
6
+ if seive[factor] :
7
+ for mult in range(factor ** 2, right + 1, factor) :
8
+ seive[mult] = False
9
10
+ primes = [x for x in range(left, right + 1) if seive[x]]
11
+ min_pair = [-1, -1]
12
+ min_pair_dist = inf
13
14
+ for x, y in zip(primes, primes[1:]) :
15
+ if y - x < min_pair_dist :
16
+ min_pair = [x, y]
17
+ min_pair_dist = y - x
18
19
+ if min_pair_dist == 2 :
20
+ break
21
22
+ return min_pair
0 commit comments