g1001_1100.s1018_binary_prefix_divisible_by_5.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
package g1001_1100.s1018_binary_prefix_divisible_by_5
// #Easy #Array #2023_05_21_Time_297_ms_(100.00%)_Space_50_MB_(100.00%)
class Solution {
fun prefixesDivBy5(nums: IntArray): List {
val result: MutableList = ArrayList(nums.size)
var remainder = 0
for (j in nums) {
remainder = (j + (remainder shl 1)) % 5
result.add(remainder == 0)
}
return result
}
}