Skip to content

Commit 57d1532

Browse files
authored
2022-08-06 update: added "Poor Pigs" (#60)
1 parent 9d93d70 commit 57d1532

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.smlnskgmail.jaman.leetcodejava.hard;
2+
3+
// https://leetcode.com/problems/poor-pigs/
4+
public class PoorPigs {
5+
6+
private final int buckets;
7+
private final int minutesToDie;
8+
private final int minutesToTest;
9+
10+
public PoorPigs(int buckets, int minutesToDie, int minutesToTest) {
11+
this.buckets = buckets;
12+
this.minutesToDie = minutesToDie;
13+
this.minutesToTest = minutesToTest;
14+
}
15+
16+
public int solution() {
17+
int time = (minutesToTest / minutesToDie) + 1;
18+
int result = 0;
19+
int total = 1;
20+
while (total < buckets) {
21+
total *= time;
22+
result++;
23+
}
24+
return result;
25+
}
26+
27+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.smlnskgmail.jaman.leetcodejava.hard;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class PoorPigsTest {
8+
9+
@Test
10+
public void defaultTest() {
11+
assertEquals(5, new PoorPigs(1000, 15, 60).solution());
12+
}
13+
14+
}

0 commit comments

Comments
 (0)