FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/C++/utf-8-validation.cpp at master · spotpan/LeetCode-Solutions · GitHub
spotpan
LeetCode-Solutions
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
C++
/
utf-8-validation.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (27 loc) · 708 Bytes
Breadcrumbs
LeetCode-Solutions
/
C++
/
utf-8-validation.cpp
Copy path
File metadata and controls
28 lines (27 loc) · 708 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
Time: O(n)
//
Space: O(1)
class
Solution
{
public:
bool
validUtf8
(vector<
int
>& data) {
int
count =
0
;
for
(
const
auto
& c : data) {
if
(count ==
0
) {
if
((c >>
5
) ==
0b110
) {
count =
1
;
}
else
if
((c >>
4
) ==
0b1110
) {
count =
2
;
}
else
if
((c >>
3
) ==
0b11110
) {
count =
3
;
}
else
if
((c >>
7
)) {
return
false
;
}
}
else
{
if
((c >>
6
) !=
0b10
) {
return
false
;
}
--count;
}
}
return
count ==
0
;
}
};
Back
|
FazBrowse Home
|
New Git URL