problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::utf_8_validation::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static bool validUtf8 (vector< int > &data)
 

详细描述

在文件 leetcode.h1723 行定义.

成员函数说明

◆ validUtf8()

bool leetcode::utf_8_validation::Solution::validUtf8 ( vector< int > &  data)
static

在文件 leetcode.cpp4465 行定义.

4465 {
4466 vector<int> len;
4467 for(const auto num: data) {
4468 if(num >> 7 == 0) {
4469 //0xxxxxxx
4470 len.push_back(1);
4471 } else if(num >> 3 == 30) {
4472 //11110xxx
4473 len.push_back(4);
4474 } else if(num >> 4 == 14) {
4475 //1110xxxx
4476 len.push_back(3);
4477 } else if(num >> 5 == 6) {
4478 //110xxxxx
4479 len.push_back(2);
4480 } else if(num >> 6 == 2) {
4481 //10xxxxxx
4482 len.push_back(-1);
4483 } else {
4484 return false;
4485 }
4486 }
4487 int count = 0;
4488 for(int i = 0; i < len.size(); i++) {
4489 if(count != 0) {
4490 if(len[i] != -1) {
4491 return false;
4492 }
4493 } else {
4494 count = len[i];
4495 if(count == -1) {
4496 return false;
4497 }
4498 }
4499 count--;
4500 }
4501 return count == 0;
4502 }

被这些函数引用 leetcode::utf_8_validation::TEST().


该类的文档由以下文件生成: