-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1018.可被-5-整除的二进制前缀.c
48 lines (32 loc) · 923 Bytes
/
1018.可被-5-整除的二进制前缀.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* @lc app=leetcode.cn id=1018 lang=c
*
* [1018] 可被 5 整除的二进制前缀
*/
// @lc code=start
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
bool* prefixesDivBy5(int* nums, int numsSize, int* returnSize){
bool *resultVector = malloc(sizeof(bool) *numsSize);
bool *resultVectorPointer = resultVector;
unsigned int targetValue = 0;
for (int *numsPointer = nums; (numsPointer < (nums + numsSize)); numsPointer++) {
targetValue <<= 1;
if ((*numsPointer) == 1) {
targetValue |= 1;
}
targetValue %= 100;
if ((targetValue % 5) == 0
) {
(*resultVectorPointer) = true;
}
else {
(*resultVectorPointer) = false;
}
resultVectorPointer++;
}
(*returnSize) = numsSize;
return resultVector;
}
// @lc code=end