Skip to content

Commit 44cbd7b

Browse files
committed
Solution to today's problem
1 parent 60fd6d8 commit 44cbd7b

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1550.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
import io.github.spannm.leetcode.LeetcodeProblem;
44

5+
import java.util.stream.IntStream;
6+
57
class Problem1550 extends LeetcodeProblem {
68

79
boolean threeConsecutiveOdds(int[] _arr) {
8-
for (int i = 0; i < _arr.length - 2; i++) {
9-
if (_arr[i] % 2 == 1 && _arr[i + 1] % 2 == 1 && _arr[i + 2] % 2 == 1) {
10-
return true;
11-
}
12-
}
13-
return false;
10+
return IntStream.range(0, _arr.length - 2).anyMatch(i -> _arr[i] % 2 == 1 && _arr[i + 1] % 2 == 1 && _arr[i + 2] % 2 == 1);
1411
}
1512

1613
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 Problem1550Test extends LeetcodeBaseTest {
9+
@ParameterizedTest(name = "[{index}] {0} --> {1}")
10+
@CsvSource(delimiter = ';', value = {
11+
"2,6,4,1; false",
12+
"1,2,34,3,4,5,7,23,12; true"
13+
})
14+
void test(@ConvertWith(CsvToIntArray.class) int[] _arr,
15+
boolean _expectedResult) {
16+
assertEquals(_expectedResult, new Problem1550().threeConsecutiveOdds(_arr));
17+
}
18+
}

0 commit comments

Comments
 (0)