当前位置:网站首页>LeetCode#204. Count prime
LeetCode#204. Count prime
2022-07-06 15:21:00 【Rufeng ZHHH】
Count all less than nonnegative integers n The number of prime numbers .
Example 1:
Input :n = 10
Output :4
explain : Less than 10 There are a total of 4 individual , They are 2, 3, 5, 7 .
Example 2:
Input :n = 0
Output :0
Example 3:
Input :n = 1
Output :0
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/count-primes
We use Eratosthene screening _ Baidu Encyclopedia
class Solution:
def countPrimes(self, n: int) -> int:
if n <3:
return 0
else:
dp=[1]*n # Create array ( First, it defaults to all primes )
dp[0],dp[1]=0,0 #0 and 1 Not prime
for i in range(2,n):
for i in range(i*i,n,i): # To optimize , from i*i Just start , Reduce duplication
dp[i]=0
return sum(dp) # Prime numbers all correspond to 1边栏推荐
- ucore lab7 同步互斥 实验报告
- ArrayList set
- Capitalize the title of leetcode simple question
- 软件测试面试回答技巧
- Want to change jobs? Do you know the seven skills you need to master in the interview software test
- Description of Vos storage space, bandwidth occupation and PPS requirements
- Réponses aux devoirs du csapp 7 8 9
- ArrayList集合
- Introduction to safety testing
- Threads et pools de threads
猜你喜欢

CSAPP家庭作业答案7 8 9章

Build your own application based on Google's open source tensorflow object detection API video object recognition system (I)

Word macro operation: convert the automatic number in the document into editable text type

全网最详细的postman接口测试教程,一篇文章满足你

How to rename multiple folders and add unified new content to folder names

C4D quick start tutorial - Introduction to software interface

The maximum number of words in the sentence of leetcode simple question

几款开源自动化测试框架优缺点对比你知道吗?

Portapack application development tutorial (XVII) nRF24L01 launch B

Mysql database (I)
随机推荐
Global and Chinese market of barrier thin film flexible electronics 2022-2028: Research Report on technology, participants, trends, market size and share
Build your own application based on Google's open source tensorflow object detection API video object recognition system (I)
Global and Chinese markets of Iam security services 2022-2028: Research Report on technology, participants, trends, market size and share
Example 071 simulates a vending machine, designs a program of the vending machine, runs the program, prompts the user, enters the options to be selected, and prompts the selected content after the use
How to write the bug report of software test?
自动化测试中敏捷测试怎么做?
UCORE lab2 physical memory management experiment report
想跳槽?面试软件测试需要掌握的7个技能你知道吗
如何成为一个好的软件测试员?绝大多数人都不知道的秘密
MySQL transactions
Jupyter installation and use tutorial
[pytorch] simple use of interpolate
ucore lab5
Build your own application based on Google's open source tensorflow object detection API video object recognition system (II)
How to become a good software tester? A secret that most people don't know
Threads and thread pools
Differences between select, poll and epoll in i/o multiplexing
UCORE LaB6 scheduler experiment report
Capitalize the title of leetcode simple question
pytest