Skip to content

Commit 9bbf1e2

Browse files
committed
add 0390 folder & cpp(12ms) version
1 parent 3d33c4f commit 9bbf1e2

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class Solution {
2+
public:
3+
bool validUtf8(vector<int>& data) {
4+
const unsigned modeContinue = 0xc0 ;
5+
6+
int conti = 0 ;
7+
for (auto it = data.begin(); it < data.end(); ++it)
8+
{
9+
10+
if (0 == conti) // 首字节
11+
{
12+
if (*it < 0x80)
13+
continue ;
14+
else if (*it < 0xe0)
15+
conti = 1 ;
16+
else if (*it < 0xf0)
17+
conti = 2 ;
18+
else if (*it < 0xf8)
19+
conti = 3 ;
20+
else
21+
return false ;
22+
}
23+
else // 后续字节
24+
{
25+
--conti ;
26+
if ((*it & modeContinue) != 0x80)
27+
return false ;
28+
}
29+
}
30+
31+
return 0 == conti ;
32+
}
33+
};

0 commit comments

Comments
 (0)