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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 18.5MB, accepted 2025-12-28.
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;
}
};