Skip to content

Commit d0231f5

Browse files
authored
Create 1018. Binary Prefix Divisible By 5 (#941)
2 parents c2c0b08 + 7d5b562 commit d0231f5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

1018. Binary Prefix Divisible By 5

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
vector<bool> prefixesDivBy5(vector<int>& nums) {
4+
vector<bool> ans;
5+
int val = 0;
6+
for (int bit : nums) {
7+
val = (val * 2 + bit) % 5;
8+
ans.push_back(val == 0);
9+
}
10+
return ans;
11+
}
12+
};

0 commit comments

Comments
 (0)