0
点赞
收藏
分享

微信扫一扫

【Leetcode_easy】717. 1-bit and 2-bit Characters

天际孤狼 2022-07-12 阅读 86

problem

​​717. 1-bit and 2-bit Characters​​

题意:
solution1:

class Solution {
public:
bool isOneBitCharacter(vector<int>& bits) {
int i=0;
while(i<bits.size()-1)
{
if(bits[i]==0) i+=1;
else i+=2;
}
return i==bits.size()-1;
}
};

solution2:根据数组的特性计算。

class Solution {
public:
bool isOneBitCharacter(vector<int>& bits) {
int i=0, n = bits.size();
while(i<n-1)
{
//if(bits[i]==0) i+=1;
//else i+=2;
i += bits[i]+1;
}
return i==n-1;
}
};

 

参考

1. ​​Leetcode_easy_717. 1-bit and 2-bit Characters​​;

2. ​​Grandyang​​;

举报

相关推荐

0 条评论