Java implementation LeetCode 717 1-bit and 2-bit characters (violence)

717.1 character bit and 2 bits

There are two special characters. The first character can be represented by a 0 bit. The second character can be two bits (10 or 11) is represented.

Now a number to a string of bits. The last character must ask whether a bit of a character. Given by the end of the string is always 0.

Example 1:

Input:
bits = [. 1, 0, 0]
Output: True
Explanation:
The only two-bit encoding scheme is a one-bit character and a character. So last character is a bit characters.
Example 2:

Input:
bits = [. 1,. 1,. 1, 0]
Output: False
Explanation:
The only two-bit character encoding scheme is two bits and characters. So last character is not one bit characters.
note:

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

class Solution {
    public boolean isOneBitCharacter(int[] bits) {
 int start = 0 ;
        while(start<bits.length-1){
            if(bits[start] == 0){
                start++;
            }else{
                start+=2;
            }
        }
        return start == bits.length-1;
    }
}
Released 1763 original articles · won praise 30000 + · views 3.92 million +

Guess you like

Origin blog.csdn.net/a1439775520/article/details/105395250