python count prime solution

  • 0

    class Solution(object):
    def countPrimes(self, n):
    count = 0
    for x in range(2, n):
    if self.issimple(x):
    count += 1
    return count
    def issimple(self, x):
    if x == 2:
    return True
    for y in range(2, x):
    if x % y == 0:
    return False
    if y * 2 > x:
    return True

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.