DIY: UTF-8 Validation
Explore how to implement UTF-8 validation by analyzing byte patterns in integer arrays. Learn the rules for 1 to 4 byte UTF-8 characters and practice writing a function to verify valid encoding, enhancing your coding interview skills.
We'll cover the following...
We'll cover the following...
Problem description
Given an integer array data, return whether it is a valid UTF-8 encoding.
A character in UTF8 can be from 1 to 4 bytes long, subject to the following rules:
- For a
1byte character, the first bit of the packet is0, followed by its Unicode code. - For an
n-bytescharacter, the firstn