add: 220313-CN [cpp]
This commit is contained in:
parent
91803365ac
commit
3768bb47e6
|
|
@ -0,0 +1,28 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
static bool validUtf8(const std::vector<int>& data) {
|
||||
int state = 0;
|
||||
for (int i : data) {
|
||||
if (state) {
|
||||
if (i < 0x80 || i > 0xBF)
|
||||
return false;
|
||||
--state;
|
||||
} else {
|
||||
if (i < 0x80) continue;
|
||||
for (int j = 0x80; i & j; j >>= 1)
|
||||
++state;
|
||||
if ((!--state) || (state > 3))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return state == 0;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
std::cout << Solution::validUtf8({235, 140, 4});
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -3,4 +3,4 @@ PROJECT(2203)
|
|||
|
||||
SET(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
ADD_EXECUTABLE(2203 220312-CN.cpp)
|
||||
ADD_EXECUTABLE(2203 220313-CN.cpp)
|
||||
|
|
|
|||
Loading…
Reference in New Issue