Tap here to switch tabs
Problem
Submissions

Problem: UTF-8 Validation

med
30 min
Try to solve the UTF-8 Validation problem.

Statement

Given an integer array data representing a sequence of bytes, determine whether it is a valid UTF-88 encoding.

A character in UTF-88 can be from 11 to 44 bytes long, following these rules:

  • For a 11 byte character, the first bit is 00, followed by its Unicode code.

  • For an nn byte character where n>1n > 1, the first nn bits are all 11, the (n+1)(n + 1)th bit is 00, followed by n−1n - 1 continuation bytes. Each continuation byte must have its most significant 22 bits set to 1010.

Note: Only the least significant 88 bits of each integer in data are considered.

Constraints:

  • 1≤1 \leq data.length ≤2imes104\leq 2 imes 10^4

  • 0≤0 \leq data[i] ≤255\leq 255

⋮
Tap here to switch tabs
Problem
Submissions

Problem: UTF-8 Validation

med
30 min
Try to solve the UTF-8 Validation problem.

Statement

Given an integer array data representing a sequence of bytes, determine whether it is a valid UTF-88 encoding.

A character in UTF-88 can be from 11 to 44 bytes long, following these rules:

  • For a 11 byte character, the first bit is 00, followed by its Unicode code.

  • For an nn byte character where n>1n > 1, the first nn bits are all 11, the (n+1)(n + 1)th bit is 00, followed by n−1n - 1 continuation bytes. Each continuation byte must have its most significant 22 bits set to 1010.

Note: Only the least significant 88 bits of each integer in data are considered.

Constraints:

  • 1≤1 \leq data.length ≤2imes104\leq 2 imes 10^4

  • 0≤0 \leq data[i] ≤255\leq 255