【Leetcode_easy】717. 1-bit and 2-bit Characters
2024-09-05 03:47:07
problem
717. 1-bit and 2-bit Characters
题意:
solution1:
class Solution {
public:
bool isOneBitCharacter(vector<int>& bits) {
int i=;
while(i<bits.size()-)
{
if(bits[i]==) i+=;
else i+=;
}
return i==bits.size()-;
}
};
solution2:根据数组的特性计算。
class Solution {
public:
bool isOneBitCharacter(vector<int>& bits) {
int i=, n = bits.size();
while(i<n-)
{
//if(bits[i]==0) i+=1;
//else i+=2;
i += bits[i]+;
}
return i==n-;
}
};
参考
1. Leetcode_easy_717. 1-bit and 2-bit Characters;
2. Grandyang;
完
最新文章
- 跨界玩AR,迪奥、Hugo Boss等知名奢侈品牌将制造AR眼镜
- linux 下查看某个端口是否被占用
- fastjson格式化bean的简易属性过滤器
- [转]SIP穿越NAT&;FireWall解决方案
- Android为ViewPager增加切换动画——使用属性动画.
- MS Sqlserver 备份数据库SQL
- GoldenGate单向复制配置示例
- apicloud+融云实现即时通讯
- linux下启动和关闭网卡命令及DHCP上网
- 一个简单的模板引(han)擎(shu)
- 转 [分享一个SQL] 查会话阻塞关系,层次关系.
- APUE学习心得
- OWIN的概念初接触
- mysql 5.7 Warning: Using a password on the command line interface can be insecure. 解决方案
- C#创建、读写、增加、删除XML操作
- Android UI(五)云通讯录项目之联系人列表,带侧滑选择,带搜索框
- GCC卡常
- git使用简明教程
- Can't use Subversion command line client***Probably the path to Subversion executable is wrong. Fix
- SQL语句--查询任务