1-bit and 2-bit Characters问题及解法
来源:互联网 发布:php mysql 扩展 编辑:程序博客网 时间:2024/06/05 08:42
问题描述:
We have two special characters. The first character can be represented by one bit 0
. The second character can be represented by two bits (10
or 11
).
Now given a string represented by several bits. Return whether the last character must be a one-bit character or not. The given string will always end with a zero.
示例:
Input: bits = [1, 0, 0]Output: TrueExplanation: The only way to decode it is two-bit character and one-bit character. So the last character is one-bit character.
Input: bits = [1, 1, 1, 0]Output: FalseExplanation: The only way to decode it is two-bit character and two-bit character. So the last character is NOT one-bit character.
问题分析:
每次记录最后出现的字符是否为只有0构成的,最终返回记录标识即可。
过程详见代码:
class Solution {public: bool isOneBitCharacter(vector<int>& bits) { bool res = 0;for (int i = 0; i < bits.size();){if (!bits[i]){i++;res = 1;}else{i += 2;res = 0;}}return res; }};
阅读全文
0 0
- 1-bit and 2-bit Characters问题及解法
- 717. 1-bit and 2-bit Characters
- 717. 1-bit and 2-bit Characters
- 717. 1-bit and 2-bit Characters
- 1-bit and 2-bit Characters
- 717. 1-bit and 2-bit Characters
- leetCode-1-bit and 2-bit Characters
- 717 1-bit and 2-bit Characters
- 717. 1-bit and 2-bit Characters
- 717. 1-bit and 2-bit Characters
- 1-bit and 2-bit Characters(leetcode)
- 717. 1-bit and 2-bit Characters。
- 717. 1-bit and 2-bit Characters
- LWC 56:717. 1-bit and 2-bit Characters
- 717. 1-bit and 2-bit Characters(第九周)
- LeetCode.717 1-bit and 2-bit Characters
- LeetCode717. 1-bit and 2-bit Characters 解题
- LeetCode-717. 1-bit and 2-bit Characters
- 宋宝华:LEP(Linux易用剖析器) 是什么,为什么以及怎么办(2)
- Python机器学习实战教程
- pb中函数大全
- 从单亲家庭内向小男生到哈佛耶鲁全奖,百万年薪的“男神学长”活出了一部励志偶像剧!
- 搜索智能提示suggestion,附近地点搜索
- 1-bit and 2-bit Characters问题及解法
- 决策树(Decision Tree)
- 异常----Exception in thread "main" java.lang.StackOverflowError
- 进程和线程的联系和区别
- UVa11107
- 编程感悟
- hbase和RDBMS的区别
- 2017-10-29C#新龟兔赛跑——没做出来
- Spring4框架----aop编程思想(03)