简单过头了.
代码:
// LeetCode Problem No.717 1-bit and 2-bit Characters (1比特与2比特字符)
// by Gun7Sum a.k.a. john11, 2022.04.17
bool isOneBitCharacter(int *bits, int bitsSize)
{
int pos=0, lastBit;
while(pos < bitsSize) {
switch(bits[pos]) {
case 0:
lastBit = 0;
pos++;
break;
case 1:
lastBit = 1;
pos += 2;
break;
}
}
return (lastBit == 0) ? true : false;
}
(话说这道题在英文站是663赞1710踩, 似乎真的是因为太水了)