当前位置: 首页 > news >正文

Python | Leetcode Python题解之第393题UTF-8编码验证

题目:

题解:

class Solution:def validUtf8(self, data: List[int]) -> bool:MASK1, MASK2 = 1 << 7, (1 << 7) | (1 << 6)def getBytes(num: int) -> int:if (num & MASK1) == 0:return 1n, mask = 0, MASK1while num & mask:n += 1if n > 4:return -1mask >>= 1return n if n >= 2 else -1index, m = 0, len(data)while index < m:n = getBytes(data[index])if n < 0 or index + n > m or any((ch & MASK2) != MASK1 for ch in data[index + 1: index + n]):return Falseindex += nreturn True

http://www.mrgr.cn/news/19273.html

相关文章:

  • 如何选择SSD
  • IBM企业流程框架方法论-附PPT下载
  • 查看端口被占用情况
  • 读软件开发安全之道:概念、设计与实施17读后总结与感想兼导读
  • 山东省行政执法证照片要求及图像处理方法
  • 基于web设备管理系统设计与实现
  • GPU版pytorch安装(win/linux)
  • JS中【async】和【defer】属性详解与区别
  • 4.3 Sensors -- onLongPress
  • C++ | Leetcode C++题解之第394题字符串解码
  • 数据结构之链表
  • Python Tkinter小程序
  • 分类预测|基于蜣螂优化极限梯度提升决策树的数据分类预测Matlab程序DBO-Xgboost 多特征输入单输出 含基础模型
  • 浏览器自动化测试的利器:Cypress
  • SPI总线协议详解
  • Golang | Leetcode Golang题解之第394题字符串解码
  • 高效异步编程:使用Python的asyncio库实现异步I/O操作
  • 我找到了一个让ChatGPT稳定通过草莓测试的方法,百试百灵!
  • 【conda】Conda 环境迁移指南:如何更改 envs_dirs 和 pkgs_dirs 以及跨盘迁移
  • 深度学习应用 - 语音识别篇