C#LeetCode刷题之#717-1比特与2比特字符（ 1-bit and 2-bit Characters）

1 <= len(bits) <= 1000.
bits[i] 总是0 或 1.

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: True

Explanation: 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: 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.

```public class Program {

public static void Main(string[] args) {
int[] nums = null;

nums = new int[] { 1, 1, 1, 0 };
var res = IsOneBitCharacter(nums);
Console.WriteLine(res);

Console.ReadKey();
}

private static bool IsOneBitCharacter(int[] bits) {
//1总是要和后面的1个数字编码，即+2，0不用编码，+1往后继续即可
//这道题做不出来主动面壁思过吧
int i = 0;
while(i < bits.Length - 1) {
i = bits[i] == 0 ? ++i : i + 2;
}
return i == bits.Length - 1;
}

}```

`False`