[LeetCode&Python] Problem 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.
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 always0or1.
class Solution(object):
def isOneBitCharacter(self, bits):
"""
:type bits: List[int]
:rtype: bool
"""
i=0
while i<len(bits)-1:
i+=bits[i]+1
return i==len(bits)-1
[LeetCode&Python] Problem 717. 1-bit and 2-bit Characters的更多相关文章
- [LeetCode&Python] Problem 108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Fo ...
- [LeetCode&Python] Problem 387. First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...
- [LeetCode&Python] Problem 427. Construct Quad Tree
We want to use quad trees to store an N x N boolean grid. Each cell in the grid can only be true or ...
- [LeetCode&Python] Problem 371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...
- [LeetCode&Python] Problem 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...
- [LeetCode&Python] Problem 226. Invert Binary Tree
Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 Tr ...
- [LeetCode&Python] Problem 905: Sort Array By Parity
Given an array A of non-negative integers, return an array consisting of all the even elements of A, ...
- [LeetCode&Python] Problem 1: Two Sum
Problem Description: Given an array of integers, return indices of the two numbers such that they ad ...
- [LeetCode&Python] Problem 682. Baseball Game
You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...
随机推荐
- Python标准数据类型的二次加工
基于类继承的原理实现: class Li(list): #继承标准数据类型 list def app(self,p_object): #派生出新的 append功能 if not isinstance ...
- 常用java命令
javap 反编译 javap xxx.class 查看大概 javap -v -p xxx.class 查看详细 jps 查看有哪些java进程 jinfo 查看或设置java进程的 vm 参数,只 ...
- python列表反转函数
def reverse(ListInput): RevList=[] for i in range (len(ListInput)): RevList.append(ListInput.pop()) ...
- net core 上传并使用EPPlus导入Excel文件
1. cshtml页面 form <form id="form" method="post" action="/SaveValueBatch& ...
- Dom方法,解析XML文件
Dom方法,解析XML文件的基本操作 package com.demo.xml.jaxp; import java.io.IOException; import javax.xml.parsers.D ...
- Springboot+MyBatis+mysql+jsp页面跳转详细示例
SpringBoot与MyBatis搭建环境,底层数据库为mysql,页面使用JSP(官网上不推荐使用jsp),完成从数据库中查询出数据,在jsp页面中显示,并且实现页面的跳转功能. 项 ...
- Windows系统上设置 Git Bash 的 Font 及 Locale
在windows 上使用 Git Bash 可以获得 unix 命令 操作体验. 但是初始的Git Bash的字体及语系都很不方便,需要自己设置. 在Git Bash的命令窗体上边框点击鼠标右键可以进 ...
- 【转载】Maven中的BOM概念
1.概述 1.1.什么是 BOM? BOM stands for Bill Of Materials. A BOM is a special kind of POM that is used to c ...
- java开发简易计算器
所选用的编译工具为NetBeans /* * To change this license header, choose License Headers in Project Properties. ...
- turtle
画一组同切圆 输入 import turtle turtle.color('red') turtle.circle(30) turtle.circle(60) turtle.circle(90) tu ...