一种是Brute force,O(nlogn) 另一种是找规律O(n),见http://hawstein.com/posts/20.4.html 当某一位的数字小于2时,那么该位出现2的次数为:更高位数字x当前位数 当某一位的数字大于2时,那么该位出现2的次数为:(更高位数字+1)x当前位数 当某一位的数字等于2时,那么该位出现2的次数为:更高位数字x当前位数+低位数字+1 package Hard; /** * Write a method to count the number of 2s…
题目大意 https://leetcode.com/problems/count-primes/description/ 204. Count Primes Count the number of prime numbers less than a non-negative number, n. Example: Input: 10Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.…