diff --git a/cpp/2203/220313-CN.cpp b/cpp/2203/220313-CN.cpp new file mode 100644 index 0000000..4435a81 --- /dev/null +++ b/cpp/2203/220313-CN.cpp @@ -0,0 +1,28 @@ +#include +#include + +class Solution { +public: + static bool validUtf8(const std::vector& 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; +} diff --git a/cpp/2203/CMakeLists.txt b/cpp/2203/CMakeLists.txt index 9701b8c..fa77a8d 100644 --- a/cpp/2203/CMakeLists.txt +++ b/cpp/2203/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2203) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2203 220312-CN.cpp) +ADD_EXECUTABLE(2203 220313-CN.cpp)