Leetcode Note: Go - Binary Prefix Divisible by 5

Binary Prefix Divisible By 5 - LeetCode
https://leetcode.com/problems/binary-prefix-divisible-by-5/

  • Go 言語で取り組んだメモ

回答

Golang easy solution 8ms 100% - LeetCode Discuss
https://leetcode.com/problems/binary-prefix-divisible-by-5/discuss/1648540/Golang-easy-solution-8ms-100

func prefixesDivBy5(nums []int) []bool {
    ans := make([]bool, len(nums))
    var t int
    for i, num := range nums {
        t = t << 1 + num
        if t % 5 == 0 {
            ans[i] = true
            t = 0
        } else {
            t %= 5
        }
    }
    return ans
}