def countPrimes(n: int) -> int:
res = []
for i in range(2, n+1):
for j in range(2, int(i ** 0.5) + 1)##for j in range(2,i):
if i % j == 0:
break
else:
# print(i)
res.append(i)
return res
参考资料:
https://leetcode-cn.com/problems/count-primes/solution/qiu-zhi-shu-chao-guo-90-by-powcai/
网友评论