0393. UTF-8 Validation
https://leetcode.com/problems/utf-8-validation
Description
Given an integer array data
representing the data, return whether it is a valid UTF-8 encoding.
A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:
For a 1-byte character, the first bit is a
0
, followed by its Unicode code.For an n-bytes character, the first
n
bits are all one's, then + 1
bit is0
, followed byn - 1
bytes with the most significant2
bits being10
.
This is how the UTF-8 encoding would work:
Note: The input is an array of integers. Only the least significant 8 bits of each integer is used to store the data. This means each integer represents only 1 byte of data.
Example 1:
Example 2:
Constraints:
1 <= data.length <= 2 * 104
0 <= data[i] <= 255
ac
Last updated