-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path393.cpp
More file actions
29 lines (29 loc) · 735 Bytes
/
Copy path393.cpp
File metadata and controls
29 lines (29 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
// Runtime: 16 ms, faster than 79.20% of C++ online submissions for UTF-8
// Validation. Memory Usage: 9.5 MB, less than 59.65% of C++ online
// submissions for UTF-8 Validation.
public:
bool validUtf8(vector<int> &data) {
int status = 0;
for (auto val : data) {
auto d = val & 0xff;
if (status) {
if (not((d >> 6) == 0b10))
return false;
--status;
} else {
if ((d >> 7) == 0)
;
else if ((d >> 5) == 0b110)
status += 1;
else if ((d >> 4) == 0b1110)
status += 2;
else if ((d >> 3) == 0b11110)
status += 3;
else
return false;
}
}
return status == 0;
}
};