zoukankan      html  css  js  c++  java
  • 717. 1-bit and 2-bit Characters

    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.

    有两种字符,第一种是单个0第二种是10或者11,问给一个01数组,,最后结尾是不是第一种字符。

    从0开始遍历数组,直到len(bits) - 2,如果当前位是1,那就i+=2否则i+1,最后看i是否还剩余最后一位。

    100->i = 2 true

    1110->i=4 false

    class Solution(object):
        def isOneBitCharacter(self, bits):
            """
            :type bits: List[int]
            :rtype: bool
            """
            i = 0
            while i < len(bits) - 1:
                if bits[i] == 1:
                    i += 1
                i += 1
            return i == len(bits) - 1
  • 相关阅读:
    slenium截屏
    效率提升
    R语言网页爬虫
    高性能计算
    数据操作
    数据库操作
    面向对象编程
    元编程
    R 的内部机制
    数据处理
  • 原文地址:https://www.cnblogs.com/whatyouthink/p/13302321.html
Copyright © 2011-2022 走看看