{ "cells": [ { "cell_type": "markdown", "source": [ "Given an array `A` of `0`s and `1`s, consider `N_i`: the i-th subarray from\n", "`A[0]` to `A[i]` interpreted as a binary number (from most-significant-bit to\n", "least-significant-bit.)\n", "\n", "Return a list of booleans `answer`, where `answer[i]` is `true` if and only if\n", "`N_i` is divisible by 5.\n", "\n", "**Example 1:**\n", "\n", "\n", "\n", " Input: [0,1,1]\n", " Output: [true,false,false]\n", " Explanation:\n", " The input numbers in binary are 0, 01, 011; which are 0, 1, and 3 in base-10. Only the first number is divisible by 5, so answer[0] is true.\n", "\n", "\n", "**Example 2:**\n", "\n", "\n", "\n", " Input: [1,1,1]\n", " Output: [false,false,false]\n", "\n", "\n", "**Example 3:**\n", "\n", "\n", "\n", " Input: [0,1,1,1,1,1]\n", " Output: [true,false,false,false,true,false]\n", "\n", "\n", "**Example 4:**\n", "\n", "\n", "\n", " Input: [1,1,1,0,1]\n", " Output: [false,false,false,false,false]\n", "\n", "\n", "\n", "\n", "**Note:**\n", "\n", " 1. `1 <= A.length <= 30000`\n", " 2. `A[i]` is `0` or `1`" ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "prefixes_div_by5 (generic function with 1 method)" }, "metadata": {}, "execution_count": 1 } ], "cell_type": "code", "source": [ "# @lc code=start\n", "using LeetCode\n", "\n", "function prefixes_div_by5(nums::Vector{Int})\n", " len = length(nums)\n", " res = fill(false, len)\n", " cur = 0\n", " for i in 1:len\n", " cur = cur * 2 + nums[i]\n", " cur % 5 == 0 && (res[i] = true)\n", " end\n", " return res\n", "end\n", "# @lc code=end" ], "metadata": {}, "execution_count": 1 }, { "cell_type": "markdown", "source": [ "---\n", "\n", "*This notebook was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*" ], "metadata": {} } ], "nbformat_minor": 3, "metadata": { "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.10.1" }, "kernelspec": { "name": "julia-1.10", "display_name": "Julia 1.10.1", "language": "julia" } }, "nbformat": 4 }