deno.land / x / masx200_leetcode_test@10.6.5 / utf-8-validation / index.ts

نووسراو ببینە
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
30
31
32
33
34
35
36
37
38
39
function validUtf8(data: number[]): boolean { for (let i = 0; i < data.length; i++) { const value = data[i]; if (value >> 7 === 0) { continue; } if ( value >> 5 === 0b110 && i + 1 < data.length && data[i + 1] >> 6 === 0b10 ) { i++; continue; } if ( value >> 4 === 0b1110 && i + 2 < data.length && data[i + 1] >> 6 === 0b10 && data[i + 2] >> 6 === 0b10 ) { i += 2; continue; } if ( value >> 3 === 0b11110 && i + 3 < data.length && [data[i + 1], data[i + 2], data[i + 3]].every( (v) => v >> 6 === 0b10, ) ) { i += 3; continue; } return false; } return true;}export default validUtf8;
masx200_leetcode_test
leetcode题解和一些测试工具
DocumentationDocumentation
GitHub Repositorymasx200/leetcode-test
GitHub Stars
4

Version Info

Tagged at
4 months ago