Solution
public class Solution {
public int countPrimes(int n) {
if (n <= 1) return 0;
HashSet<Integer> set = new HashSet<Integer>();
int result = 0;
for (int i = 2; i < n; i++) {
if (!set.contains(i)) {
result++;
for (int j = 0; j * i < n; j++) {
set.add(j * i);
}
}
}
return result;
}
}
Problem#1
- 超出时间限制
- 差一点点