Skip to content

Commit efa9c34

Browse files
committed
More solutions and unit tests
1 parent 24877e0 commit efa9c34

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0488.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44

55
class Problem0488 extends LeetcodeProblem {
66

7-
private final int maxcount = 6;
7+
private static final int MAX_COUNT = 6;
88

9-
public int findMinStep(String _board, String _hand) {
9+
int findMinStep(String _board, String _hand) {
1010
int[] handCount = new int[26];
1111
for (int i = 0; i < _hand.length(); i++) {
12-
++handCount[_hand.charAt(i) - 'A'];
12+
handCount[_hand.charAt(i) - 'A']++;
1313
}
1414
int result = dfs(_board + "#", handCount);
15-
return result == maxcount ? -1 : result;
15+
return result == MAX_COUNT ? -1 : result;
1616
}
1717

18-
private int dfs(String _s, int[] _handCount) {
18+
static int dfs(String _s, int[] _handCount) {
1919
_s = removeConsecutive(_s);
2020
if ("#".equals(_s)) {
2121
return 0;
2222
}
23-
int result = maxcount;
23+
int result = MAX_COUNT;
2424
int need = 0;
2525
for (int i = 0, j = 0; j < _s.length(); j++) {
2626
if (_s.charAt(j) == _s.charAt(i)) {
@@ -37,7 +37,7 @@ private int dfs(String _s, int[] _handCount) {
3737
return result;
3838
}
3939

40-
private String removeConsecutive(String _board) {
40+
static String removeConsecutive(String _board) {
4141
for (int i = 0, j = 0; j < _board.length(); j++) {
4242
if (_board.charAt(j) == _board.charAt(i)) {
4343
continue;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.github.spannm.leetcode.lc1.lc1200;
2+
3+
import io.github.spannm.leetcode.LeetcodeBaseTest;
4+
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.converter.ConvertWith;
6+
import org.junit.jupiter.params.provider.CsvSource;
7+
8+
class Problem1248Test extends LeetcodeBaseTest {
9+
@ParameterizedTest(name = "[{index}] {0}; {1} --> {2}")
10+
@CsvSource(delimiter = ';', value = {
11+
"1,1,2,1,1; 3; 2",
12+
"2,4,6; 1 ; 0",
13+
"2,2,2,1,2,2,1,2,2,2; 2; 16"
14+
})
15+
void test(@ConvertWith(CsvToIntArray.class) int[] _nums, int _k, int _expectedResult) {
16+
assertEquals(_expectedResult, new Problem1248().numberOfSubarrays(_nums, _k));
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.github.spannm.leetcode.lc1.lc1500;
2+
3+
import io.github.spannm.leetcode.LeetcodeBaseTest;
4+
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.converter.ConvertWith;
6+
import org.junit.jupiter.params.provider.CsvSource;
7+
8+
class Problem1552Test extends LeetcodeBaseTest {
9+
@ParameterizedTest(name = "[{index}] {0}; {1} --> {2}")
10+
@CsvSource(delimiter = ';', value = {
11+
"1,2,3,4,7; 3; 3",
12+
"5,4,3,2,1,1000000000; 2; 999999999"
13+
})
14+
void test(@ConvertWith(CsvToIntArray.class) int[] _basketPositions, int _nbBalls, int _expectedResult) {
15+
assertEquals(_expectedResult, new Problem1552().maxDistance(_basketPositions, _nbBalls));
16+
}
17+
}

0 commit comments

Comments
 (0)