```
class Solution:
# @param {integer} n
# @return {integer}
def countPrimes(self, n):
flag = [True for i in range(n)]
base = 2
while base * base < n:
i = 2
while i * base < n:
flag[i*base] = False
i += 1
base += 1
while flag[base] == False and base * base < n:
base += 1
res = 0
for i in range(2, n):
if flag[i]:
res += 1
return res
```

Could anyone tell me why my code is memory limited exceed, and I just follow the hint.

Many thanks!