[抄题]:

Count the number of prime numbers less than a non-negative number, n.

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

[一句话思路]:

质数的倍数是合数

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

质数的倍数是合数

[复杂度]:Time complexity: O(n) Space complexity: O(1)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

class Solution {
public int countPrimes(int n) {
//cc
if (n < 2) {
return 0;
} //ini
int count = 0;//prime num
int[] notPrime = new int[n];//not prime num //for i, i * j
for (int i = 2; i < n; i++) {
if (notPrime[i] == 0) count++;
for (int j = 2; i * j < n; j++) {
notPrime[i * j] = 1;
}
} return count;
}
}

204. Count Primes 统计<n的质数的个数的更多相关文章

  1. [leetcode] 204. Count Primes 统计小于非负整数n的素数的个数

    题目大意 https://leetcode.com/problems/count-primes/description/ 204. Count Primes Count the number of p ...

  2. leetcode 263. Ugly Number 、264. Ugly Number II 、313. Super Ugly Number 、204. Count Primes

    263. Ugly Number 注意:1.小于等于0都不属于丑数 2.while循环的判断不是num >= 0, 而是能被2 .3.5整除,即能被整除才去除这些数 class Solution ...

  3. 204. Count Primes - LeetCode

    Queston 204. Count Primes Solution 题目大意:给一个数,求小于这个数的素数的个数 思路:初始化一个boolean数组,初始设置为true,先遍历将2的倍数设置为fal ...

  4. [LeetCode] 204. Count Primes 质数的个数

    Count the number of prime numbers less than a non-negative number, n. Example: Input: 10 Output: 4 E ...

  5. 【LeetCode】 204. Count Primes 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 素数筛法 参考资料 日期 [LeetCode] 题目 ...

  6. [LeetCode] 204. Count Primes 解题思路

    Count the number of prime numbers less than a non-negative number, n. 问题:找出所有小于 n 的素数. 题目很简洁,但是算法实现的 ...

  7. 【刷题-LeetCode】204. Count Primes

    Count Primes Count the number of prime numbers less than a non-negative number, *n*. Example: Input: ...

  8. LeetCode 204. Count Primes计数质数 (C++)

    题目: Count the number of prime numbers less than a non-negative number, n. Example: Input: 10 Output: ...

  9. [LeetCode] 204. Count Primes 计数质数

    Description: Count the number of prime numbers less than a non-negative number, n click to show more ...

随机推荐

  1. SQLyog中的计算适合的数据类型

    可能使用的数据库工作比较杂吧(机器上有toad.PLSQL Developer.Navicat.SQLyog等).并非是觉得那种都不好用,而是觉得有适合大部分需求的,但也有工具在某一方面特别方便的. ...

  2. tlflearn 编码解码器 ——数据降维用

    # -*- coding: utf-8 -*- """ Auto Encoder Example. Using an auto encoder on MNIST hand ...

  3. (转)android头像设置:从本地照片库或拍照获取并剪裁

    本文转载于:http://blog.csdn.net/sheeprunning/article/details/9184021 功能介绍 制作android应用时,用户注册的功能必不可少,往往还需要具 ...

  4. GEF入门实例_总结_03_显示菜单和工具栏

    一.前言 本文承接上一节: GEF入门实例_总结_02_新建初始RCP空项目 这一节,我们来给我们的插件加上菜单. 二.基础知识 1.action bar.menubar.coolbar   含义 a ...

  5. LeetCode OJ:Binary Tree Inorder Traversal(中序遍历二叉树)

    Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...

  6. svn 服务器安装包下载地址

    svn 服务器安装包下载地址 https://www.visualsvn.com/server/download/

  7. mysql中获取自增函数解析

    1 如果 一条语句多行插入,默认情况下是返回第一行的自增id 2 存储过程可以与外部共享自增,而函数和触发器不能,因为在函数和触发器关闭的时候,自增自动restore 3 获取自增id,不会因为并发产 ...

  8. LeetCode 4 Keys Keyboard

    原题链接在这里:https://leetcode.com/problems/4-keys-keyboard/description/ 题目: Imagine you have a special ke ...

  9. microsoft windows network 不允许一个用户使用一个以上用户名与服务器或共享资源的多重连接

    运行CMD在命令行中运行net use * /del /y 命令中断开所有连接最后,你再次访问 ,就不会有问题了. 而且可以连接多个samba用户.

  10. EMC (电磁兼容性)

    电磁兼容性EMC(Electro Magnetic Compatibility),是指设备或系统在其电磁环境中符合要求运行并不对其环境中的任何设备产生无法忍受的电磁干扰的能力.因此,EMC包括两个方面 ...