From fe7dea1399313282c6721b1a391e646329b84eaf Mon Sep 17 00:00:00 2001 From: rituraj-abes <115390762+rituraj-abes@users.noreply.github.com> Date: Sat, 14 Oct 2023 18:17:04 +0530 Subject: [PATCH] Create leetcode204.cpp leetcode solution for question 204 --- C++/leetcode204.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 C++/leetcode204.cpp diff --git a/C++/leetcode204.cpp b/C++/leetcode204.cpp new file mode 100644 index 00000000..2ffce8e3 --- /dev/null +++ b/C++/leetcode204.cpp @@ -0,0 +1,32 @@ +/* +204. Count Primes +Given an integer n, return the number of prime numbers that are strictly less than n. +Example 1: +Input: n = 10 +Output: 4 +Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7. +*/ +class Solution { +public: + int countPrimes(int n) { + if(n == 0) + return 0; + vector prime(n,true); + prime[0] = prime [1] = false ; + int ans = 0; + for(int i = 2 ; i