Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0615791

Browse files
[ACCEPTED][Problem 1550] Three Consecutive Odds
1 parent a795b27 commit 0615791

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎src/easy/ThreeConsecutiveOdds1550.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@ package easy
22

33
object ThreeConsecutiveOdds1550 {
44
fun threeConsecutiveOdds(arr: IntArray): Boolean {
5+
var odds = 0
6+
var previousOdd = -1
7+
arr.forEach { num ->
8+
when {
9+
num.issOdd() && previousOdd.issOdd() -> {
10+
previousOdd = num
11+
odds++
12+
}
13+
14+
num % 2 == 1 -> {
15+
odds = 1
16+
previousOdd = num
17+
}
18+
19+
else -> {
20+
odds = 0
21+
previousOdd = -1
22+
}
23+
}
24+
25+
if (odds == 3)
26+
return true
27+
28+
}
29+
530
return false
631
}
32+
33+
private fun Int.issOdd() = this % 2 == 1
734
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /