leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 7c0c5f9996cad24588d40f8184f9dfc906d55bd7
parent 560b090dd56cb491ae8e97de7f00093e9767dd2f
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Tue, 23 May 2023 11:38:35 +0200

Random Problem

Diffstat:
AProblems/0204.cpp | 13+++++++++++++
MREADME.md | 1+
2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/Problems/0204.cpp b/Problems/0204.cpp @@ -0,0 +1,13 @@ +class Solution { +public: + int countPrimes(int n) { + vector<bool> sieve(n); + int res = 0; + for (long i = 2; i < n; i++) { + if (sieve[i]) continue; + for (long j = i * i; j < n; j += i) sieve[j] = true; + res++; + } + return res; + } +}; diff --git a/README.md b/README.md @@ -181,6 +181,7 @@ for solving problems. | 0201 | Medium | [Bitwise AND of Numbers Range](Problems/0201.cpp) | | 0202 | Easy | [Happy Number](Problems/0202.cpp) | | 0203 | Easy | [Remove Linked List Elements](Problems/0203.cpp) | +| 0204 | Medium | [Count Primes](Problems/0204.cpp) | | 0205 | Easy | [Isomorphic Strings](Problems/0205.cpp) | | 0206 | Easy | [Reverse Linked List](Problems/0206.cpp) | | 0207 | Medium | [Course Schedule](Problems/0207.cpp) |