204. Count Primes
Count the number of prime numbers less than a non-negative number, n.
Example:
Input: 10
Output: 4
Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.
难度:easy
题目:统计小于非负整数n的所有素数。
思路:参考素数筛选法。
Runtime: 11 ms, faster than 94.69% of Java online submissions for Count Primes.
Memory Usage: 35.9 MB, less than 21.43% of Java online submissions for Count Primes.
class Solution {public int countPrimes(int n) {boolean[] notPrimes = new boolean[n];int count = 0;for (int i = 2; i < n; i++) {if (!notPrimes[i]) {count++;for (int j = 2 * i; j < n; j += i) {notPrimes[j] = true;}}}return count;}
}
204. Count Primes相关推荐
- leetCode 204. Count Primes 哈希 求素数
204. Count Primes 求素数 Description: Count the number of prime numbers less than a non-negative number ...
- 【LeetCode 剑指offer刷题】特殊数题3:204 Count Primes
[LeetCode & 剑指offer 刷题笔记]目录(持续更新中...) 204. Count Primes Count the number of prime numbers less t ...
- [LeetCode] 204. Count Primes
204. Count Primes Count the number of prime numbers less than a non-negative number, n. Example: Inp ...
- LeetCode 204. Count Primes
注:质数从2开始,2.3-- 改进过程: 一.常规思路是对小于n的每一个数进行isPrime判断,isPrime(int x)函数中for(int i = 2; i <= x /2; ++i), ...
- letecode [204] - Count Primes
Count the number of prime numbers less than a non-negative number, n. Example: Input: 10 Output: 4 E ...
- leetcode python3 简单题204. Count Primes
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百零四题 (1)题目 英文: Count the number of prime ...
- LeetCode -- 204. Count Primes
题目标签 HashTab(哈希表) 题意及思路 题意:略 思路:有关素数的题目我所知道有两种做法.一种是最基本的isPrime算法,关键点在循环判断时,上限为Math.sqrt(n) (求n是否为素数 ...
- Leetcode-204 Count Primes
#204 Count Primes Count the number of prime numbers less than a non-negative number, n. 题解:这道题如果对每个小 ...
- LeetCode 204. Count Primes--从一开始的质数个数--Python解法--面试算法题
题目地址:Count Primes - LeetCode Count the number of prime numbers less than a non-negative number, n. E ...
最新文章
- 我自己写的3D图形数学库。。。有点乱!
- python最基本的规则是什么_2015/8/26 Python基础(1):基本规则及赋值
- Excel 2016中的新增函数之CONCAT
- 【Python】监控视频中运动目标检测的代码实现及效果展示
- 三分钟了解Mysql的表级锁——《深究Mysql锁》
- python人工智能——深度学习——TensorFlow——图和会话
- @ComponentScan配置扫描多个包
- pdfLaTeX和XeLaTeX
- AE物体表面跟踪特效合成高级插件:Lockdown for Mac
- 突破XXX,冲上Google+
- Asp.net1.0 升级 ASP.NET 2.0 的几个问题总结 (转)
- mysql可视化操作系统_MySQL的可视化操作工具workbench的安装
- 微软最近对外发布了必应翻译应用开发接口(API),Facebook成为第一批尝鲜者...
- Kruskal算法求最小生成树
- cesium添加填充_cesium实现注记功能
- 《设计模式之禅》目录
- c语言实战项目之一 贪吃蛇(源码免费开放)
- java对接支付宝支付(手机网站支付)
- ZOJ 4062 Plants vs. Zombies(二分答案)
- 2015年英语专升本英语阅读「Part II 阅读专区」【文章(图片)、答案、词汇记忆】
热门文章
- 2020高速公路shp文件_全国按轴收费方案最终版!今天起,高速公路就按这个标准收费...
- Mac修改系统用户名好方法(文件无丢失)
- 计算机不同用户信息互通吗,迷你世界电脑版和手机版通用吗 二者账号数据互通吗...
- mysql数据库安装2017_mysql——概述和安装
- activepython win32com_activepython下载
- python pip下载安装教程_Python下的常用下载安装工具pip的安装方法
- 普渡大学电子计算机专业,普渡大学电子工程(EE)专业介绍
- python如何绘制曲线图_只会柱状图、饼状图、折线图怎么行,来用Python画个热力图...
- 服务器系统2012怎么多人连接,windows2012服务器TCP连接数
- java url 处理,URL处理-Java架构师必看