LeetCode solutions

1071. Binary Prefix Divisible By 5

My accepted C++ solution to LeetCode problem 1071, Binary Prefix Divisible By 5, running in 0ms.

  • Difficulty: Easy
  • C++
  • Runtime 0ms
  • Memory 18.5MB

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 0ms, memory 18.5MB, accepted 2025-12-28.

cpp
class Solution {
public:
    vector<bool> prefixesDivBy5(vector<int>& nums) {
        vector<bool> result;
        int num = 0;
        for (int bit : nums) {
            num = (num * 2 + bit) % 5;
            result.push_back(num == 0);
        }
        return result;
    }
};

Source