Skip to content

Commit 2eb379d

Browse files
refactor 204
1 parent e4ae4ee commit 2eb379d

File tree

2 files changed

+0
-38
lines changed

2 files changed

+0
-38
lines changed

src/main/java/com/fishercoder/solutions/_204.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,6 @@ public int countPrimes(int n) {
9393
public class _204 {
9494

9595
public static class Solution1 {
96-
/**
97-
* This solution works, but takes too long and resulted in TLE on Leetcode.
98-
*/
99-
public int countPrimes(int n) {
100-
int count = 0;
101-
for (int i = 1; i < n; i++) {
102-
if (isPrime(i)) {
103-
count++;
104-
}
105-
}
106-
return count;
107-
}
108-
109-
private boolean isPrime(int k) {
110-
if (k <= 1) {
111-
return false;
112-
}
113-
for (int i = 2; i * i <= k; i++) {
114-
if (k % i == 0) {
115-
return false;
116-
}
117-
}
118-
return true;
119-
}
120-
}
121-
122-
public static class Solution2 {
12396
public int countPrimes(int n) {
12497
boolean[] notPrime = new boolean[n];
12598
int count = 0;

src/test/java/com/fishercoder/_204Test.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,66 +8,55 @@
88

99
public class _204Test {
1010
private static _204.Solution1 solution1;
11-
private static _204.Solution2 solution2;
1211

1312
@BeforeClass
1413
public static void setup() {
1514
solution1 = new _204.Solution1();
16-
solution2 = new _204.Solution2();
1715
}
1816

1917
@Test
2018
public void test1() {
2119
assertEquals(0, solution1.countPrimes(2));
22-
assertEquals(0, solution2.countPrimes(2));
2320
}
2421

2522
@Test
2623
public void test2() {
2724
assertEquals(1, solution1.countPrimes(3));
28-
assertEquals(1, solution2.countPrimes(3));
2925
}
3026

3127
@Test
3228
public void test3() {
3329
assertEquals(2, solution1.countPrimes(5));
34-
assertEquals(2, solution2.countPrimes(5));
3530
}
3631

3732
@Test
3833
public void test4() {
3934
assertEquals(114155, solution1.countPrimes(1500000));
40-
assertEquals(114155, solution2.countPrimes(1500000));
4135
}
4236

4337
@Test
4438
public void test5() {
4539
assertEquals(10, solution1.countPrimes(30));
46-
assertEquals(10, solution2.countPrimes(30));
4740
}
4841

4942
@Test
5043
public void test6() {
5144
assertEquals(4, solution1.countPrimes(10));
52-
assertEquals(4, solution2.countPrimes(10));
5345
}
5446

5547
@Test
5648
public void test7() {
5749
assertEquals(8, solution1.countPrimes(20));
58-
assertEquals(8, solution2.countPrimes(20));
5950
}
6051

6152
@Test
6253
public void test8() {
6354
assertEquals(12, solution1.countPrimes(40));
64-
assertEquals(12, solution2.countPrimes(40));
6555
}
6656

6757
@Test
6858
public void test9() {
6959
assertEquals(15, solution1.countPrimes(50));
70-
assertEquals(15, solution2.countPrimes(50));
7160
}
7261

7362
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy