其他分享
首页 > 其他分享> > 393. UTF-8 编码验证

393. UTF-8 编码验证

作者:互联网

 1 class Solution 
 2 {
 3 public:
 4     bool validUtf8(vector<int>& data) 
 5     {
 6         int n = 0;
 7         for(int i = 0;i < data.size();i ++)
 8         {
 9             if(n > 0)
10             {
11                 if(data[i]>>6 != 2)return false;
12                 n--;
13             }
14             else if(n == 0)
15             {
16                 if(data[i]>>7 == 0) n = 0;
17                 else if(data[i]>>5 == 0b110) n = 1;
18                 else if(data[i]>>4 == 0b1110) n = 2;
19                 else if(data[i]>>3 == 0b11110) n = 3;
20                 else return false;
21             }
22         }
23         return n == 0;
24     }
25 };

 

标签:编码,UTF,0b1110,int,else,393,return,false,data
来源: https://www.cnblogs.com/yuhong1103/p/12790858.html