Skip to content

Commit

Permalink
Solution to today's problem
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Jul 1, 2024
1 parent 60fd6d8 commit 44cbd7b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import io.github.spannm.leetcode.LeetcodeProblem;

import java.util.stream.IntStream;

class Problem1550 extends LeetcodeProblem {

boolean threeConsecutiveOdds(int[] _arr) {
for (int i = 0; i < _arr.length - 2; i++) {
if (_arr[i] % 2 == 1 && _arr[i + 1] % 2 == 1 && _arr[i + 2] % 2 == 1) {
return true;
}
}
return false;
return IntStream.range(0, _arr.length - 2).anyMatch(i -> _arr[i] % 2 == 1 && _arr[i + 1] % 2 == 1 && _arr[i + 2] % 2 == 1);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.github.spannm.leetcode.lc1.lc1500;

import io.github.spannm.leetcode.LeetcodeBaseTest;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.converter.ConvertWith;
import org.junit.jupiter.params.provider.CsvSource;

class Problem1550Test extends LeetcodeBaseTest {
@ParameterizedTest(name = "[{index}] {0} --> {1}")
@CsvSource(delimiter = ';', value = {
"2,6,4,1; false",
"1,2,34,3,4,5,7,23,12; true"
})
void test(@ConvertWith(CsvToIntArray.class) int[] _arr,
boolean _expectedResult) {
assertEquals(_expectedResult, new Problem1550().threeConsecutiveOdds(_arr));
}
}

0 comments on commit 44cbd7b

Please sign in to comment.