# ［LeetCode］1-bit and 2-bit Characters 1位和2位字符

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.

Example 1:

```Input:
bits = [1, 0, 0]
Output: True
Explanation:
The only way to decode it is two-bit character and one-bit character. So the last character is one-bit character.```

Example 2:

```Input:
bits = [1, 1, 1, 0]
Output: False
Explanation:
The only way to decode it is two-bit character and two-bit character. So the last character is NOT one-bit character.```

Note:

• 1 <= len(bits) <= 1000.
• bits[i] is always 0 or 1.

```class Solution {
public boolean isOneBitCharacter(int[] bits) {
int n = bits.length;
int i = 0;
while(i<n-1){
if(bits[i]==0)
i ++;
else
i += 2;
}
return i == n-1;
}
}```

0 条评论

## 相关文章

### 很实用的前端开发规范

1.标准变量命名使用驼峰式命名 eg. let thisIsMyName; 2.常量全部大写，并使用下划线连接 eg. const MAX_COUNT = 10...

1082

3034

### MySQL字符串中抽取数值的方法

MySQL的字符串函数非常多，以至于有时候我不知道该如何灵活的使用这些函数。 字符串基本信息函数 collation convert，char_len...

2898

1444

1112

850

1513

### AWK第二课

1、工作原理 例子： cat /etc/passwd |awk -F ‘:’ ‘BEGIN {print “name”} {print \$1} END {p...

3647

39711

992